1
這是一個乏味的問題。我已經構建了一個WCF以使用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;}
}
}
許多感謝閱讀
我最近使用的是一個wcf程序和使用web服務,但在我的應用程序中,我創建了一個自定義類,並在其中添加了tokennamespace。 – Antony
可能會幫助你。 http://weblog.west-wind.com/posts/2012/Nov/24/WCF-WSSecurity-and-WSE-Nonce-Authentication – Antony