2013-08-06 69 views
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;} 
    } 
} 

许多感谢阅读

+0

我最近使用的是一个wcf程序和使用web服务,但在我的应用程序中,我创建了一个自定义类,并在其中添加了tokennamespace。 – Antony

+0

可能会帮助你。 http://weblog.west-wind.com/posts/2012/Nov/24/WCF-WSSecurity-and-WSE-Nonce-Authentication – Antony

回答

0

也许这不是消息看起来像在网络上。可能WCF日志查看器添加它(你可以看到它做了一些操作,因为它删除了密码)。使用Fiddler来查看真实消息的外观。

然后您手动(通过数据合同)添加安全标头。通常WCF可以配置为通过配置绑定来完成。所以WCF可能会标识一个安全头并且总是附加一些名称空间给它。

我不担心这一点。

相关问题