这是一个有点乏味的问题..我构建了一个使用WS-Security的WCF,在我的日志中如下所示:
<h:Security xmlns:h="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<UsernameToken>
<Username>
<!-- Removed-->
</Username>
<Password>
<!-- Removed-->
</Password>
</UsernameToken>
</h:Security>问题是,为什么我会得到同一个名称空间被引用两次("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")?我知道如果同一个名称空间被引用两次并不重要,只要元素引用了正确的名称空间,但我确实想知道它为什么要这样做。
我的代码:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped = false)]
public partial class InventoryCountRequest
{
[System.ServiceModel.MessageHeaderAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public Security Security;
//Other MessageHeader and MessageBody attributes
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public partial class Security
{
private UsernameToken usernameTokenField;
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]
public UsernameToken UsernameToken
{
get{return this.usernameTokenField;}
set{this.usernameTokenField = value;}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public partial class UsernameToken
{
private string usernameField;
private Password passwordField;
[System.Xml.Serialization.XmlElementAttribute(Order = 0)]
public string Username
{
get{return this.usernameField;}
set{this.usernameField = value;}
}
[System.Xml.Serialization.XmlElementAttribute(Order = 1)]
public Password Password
{
get{return this.passwordField;}
set{this.passwordField = value;}
}
}
[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "3.0.4506.2152")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")]
public partial class Password
{
private string typeField;
private string valueField;
[System.Xml.Serialization.XmlAttributeAttribute()]
public string Type
{
get{return this.typeField;}
set{this.typeField = value;}
}
[System.Xml.Serialization.XmlTextAttribute()]
public string Value
{
get{return this.valueField;}
set{this.valueField = value;}
}
}非常感谢您阅读
发布于 2013-08-07 05:48:14
也许这不是消息在网络上的样子。可能是WCF日志查看器添加的(您可以看到它做了一些操作,因为它删除了密码)。使用Fiddler查看实际消息是什么样子。
然后手动(通过数据合约)添加安全标头。通常,可以通过配置绑定来配置WCF来执行此操作。因此,WCF可能会识别一个安全标头,并始终向其附加一些命名空间。
我不会担心这个的。
https://stackoverflow.com/questions/18085235
复制相似问题