当前位置: 首页 > 知识库问答 >
问题:

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

郭子航
2023-03-14

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

非常感谢阅读

共有1个答案

孟昆
2023-03-14

也许这不是网络上消息的样子。可能是WCF日志查看器添加了它(你可以看到它删除了密码后做了一些操作)。使用Fiddler看看真正的消息是什么样子。

然后您手动(通过数据合同)添加安全头。一般来说,WCF可以通过绑定的配置来配置。所以也许WCF识别一个安全头,并总是给它附加一些命名空间。

我不会担心的。

 类似资料:
  • 在这一章,我们将看看怎么创建一个命名空间配置来使用框架的主要功能。让我们假设你想要快速的使用命名空间配置添加验证支持和访问控制和一些测试的登录到一个已经存在的网站应用程序。然后我们看看如何将验证换刀数据库和其他的安全仓库。在后续章节我们将介绍更多高级的命名空间配置选项。 web.xml 配置 你需要做的第一件事情是添加下面的过滤器定义到你的web.xml 文件: <filter> <filter-

  • 我有一个跨两个定义的复杂类型。XSD文件。 Parent.xsd: 嵌入式.xsd: 我的XML看起来像这样: 有没有办法改变事物,使嵌入的两个元素具有相同的前缀?我不能将嵌入类型复制到父对象中。外部原因的xsd。此外,不加区分地消除emb前缀的所有使用的解决方案将不起作用。

  • 命名空间是设计用来扑捉框架最常见用途和提供一个简化和简介的语法用来在应用程序中打开他们。设计是基于框架中的大规模依赖,并且可以划分为以下几个方面: Web/HTTP 安全- 最复杂的部分,设置过滤器和应用框架验证机制的相关服务bean,渲染登录和错误页面等等。 业务对象(方法)安全 - 业务层安全选项. AuthenticationManager - 处理来自框架其他部分的认证请求 AccessD

  • 从2.0版本开始Spring Security 改进了对服务层方法的安全支持,它提供了对JSR-250注解安全支持以及框架的原生@Secured注解的支持。从3.0开始你也可以使用新的基于表达式的注解。你可以将安全应用到单个bean.使用intercept-methods元素装饰Bean的声明。或者你可以在使用AspectJ风格的切入点应用安全到整个服务层的多个Bean类。 <global-met

  • 我使用CXF从WSDL/XSD生成java类,然后返回XML(用于JMS)。 在生成的一个类中,它表示:

  • Testing Method Security This section demonstrates how to use Spring Security’s Test support to test method based security. We first introduce a MessageService that requires the user to be authenticate