WCF-Soap标头在安全元素中两次引用命名空间
本文关键字:两次 命名空间 引用 安全 元素 WCF-Soap | 更新日期: 2023-09-27 18:26:34
这是一个有点乏味的问题。。我已经构建了一个WCF来使用WS-Security,在我的日志中如下所示:
<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;}
}
}
非常感谢您阅读
也许这不是消息在网络上的样子。WCF日志查看器可能添加了它(您可以看到它在删除密码后进行了一些操作)。使用Fiddler查看真实消息的外观。
然后手动(通过数据合约)添加安全标头。通常,WCF可以通过绑定的配置来进行配置。因此,也许WCF标识了一个安全标头,并总是为其附加一些命名空间
我不会担心的。