【发布时间】:2013-08-07 18:11:46
【问题描述】:
这是一个有点乏味的问题。我已经构建了一个 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 程序并使用 Web 服务,但在我的应用程序中,我正在创建一个自定义类并在其中添加令牌命名空间。
-
也许这会对你有所帮助。 weblog.west-wind.com/posts/2012/Nov/24/…
标签: c# wcf soap ws-security soapheader