C# WCF-Soap头在安全元素中引用命名空间两次

C# WCF-Soap头在安全元素中引用命名空间两次,c#,wcf,soap,ws-security,soapheader,C#,Wcf,Soap,Ws Security,Soapheader,这是一个有点乏味的问题。。我已经构建了一个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-sec

这是一个有点乏味的问题。。我已经构建了一个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>

非常感谢您阅读

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

然后,您可以通过数据契约手动添加安全标头。通常,WCF可以通过配置绑定来配置。因此,WCF可能会标识一个安全头,并始终为其附加一些名称空间


我不担心这一点。

我最近使用了一个wcf程序并使用了一个Web服务,但在我的应用程序中,我创建了一个customclass,并在其中添加了tokennamespace。这可能会对您有所帮助。
[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;}
  }
}