Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#.NET 4.0 WCF MessageSecurityException,“;安全标头为空。”;使用服务时_C#_.net_Wcf_Visual Studio 2010_Soap - Fatal编程技术网

C#.NET 4.0 WCF MessageSecurityException,“;安全标头为空。”;使用服务时

C#.NET 4.0 WCF MessageSecurityException,“;安全标头为空。”;使用服务时,c#,.net,wcf,visual-studio-2010,soap,C#,.net,Wcf,Visual Studio 2010,Soap,在一个项目中使用WCF和C#时,我得到一个异常消息MessageSecurityException,消息为“Security header is empty”。以下是响应(根据MS Service Trace Viewer): 除了如何关闭安全标头之外,它们几乎完全相同。这很有趣,但不应该引发异常 我还发现了一个解决方案,其中的解决方案是创建一个自定义消息编码器,并剥离整个安全头,尽管这会起作用,但这是一个额外的不必要的步骤。这是使用.Net和WCF的唯一方法吗?WCF不能处理没有内容的安全标头

在一个项目中使用WCF和C#时,我得到一个异常消息MessageSecurityException,消息为“Security header is empty”。以下是响应(根据MS Service Trace Viewer):

除了如何关闭安全标头之外,它们几乎完全相同。这很有趣,但不应该引发异常

我还发现了一个解决方案,其中的解决方案是创建一个自定义消息编码器,并剥离整个安全头,尽管这会起作用,但这是一个额外的不必要的步骤。这是使用.Net和WCF的唯一方法吗?WCF不能处理没有内容的安全标头吗

编辑: 澄清问题,编写一个丢弃安全头的编码器是否是使用WCF接收和解析带有空安全头的SOAP消息的唯一方法

编辑2:添加部分配置:

    <binding name="NinjaBinding">
      <security allowSerializedSigningTokenOnReply="true" enableUnsecuredResponse="true"
      authenticationMode="UserNameOverTransport" requireDerivedKeys="false"
      securityHeaderLayout="Lax" includeTimestamp="false" allowInsecureTransport="true"
      keyEntropyMode="ClientEntropy"
      messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
      requireSecurityContextCancellation="false">
        <localServiceSettings detectReplays="false" />
        <secureConversationBootstrap _IDENTICAL_TO_ABOVE_
        </secureConversationBootstrap>
      </security>
      <textMessageEncoding />
      <httpsTransport />
    </binding>

(现在我回答我自己的问题,因为我已经能够得出某种答案)

简而言之,否您不能将WCF“开箱即用”(即通过*.config)用于在响应中提供空安全头的应用程序服务器。您必须实现一个编码器,该编码器将消息修改为WCF框架可接受的格式

欲了解更多信息,请阅读包含编码器及其应用程序的非常好的演练。还提供了一个能够解决我的问题的代码片段,即修改安全标头


我想知道为什么MS和Oracle产品永远不能和平共存:D

您的客户机的安全配置是什么?您使用的是WCF服务还是非WCF服务?即使安全标头为空,它是否也包含?请求中使用了什么安全性?安全配置,基本上只是
UserNameOverTransport
和https传输绑定,根据ws-spec,其余的应该无关紧要(我已经查看了每个App.config设置AFAIK)。通过SOAP实现非WCF。为什么包含标题?我不知道?但是我的客户机正在使用服务器。req中的安全性,与conf相同。问题是:您是否必须编写自定义消息编码器,或者是否可以通过某种方式配置WCF以删除安全标头而不实现编码器?您的意思是您使用的安全模式=Transport或TransportWithMessageCredential?据我所知,安全模式不适用于httpsTransport。BasicHttpBinding是为数不多的有此功能的产品之一。或者?问题是WS-Security规范是否允许此标头为空。我没有找到明确的答案,我也没有,但是没有任何东西表明它不能为空并且包含设置为true的mustUnderstand属性。
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing">
   <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="true" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"/>
      <wsa:Action>_WHAT_I_DID_</wsa:Action>
      <wsa:RelatesTo>_REQ_MSG_ID_</wsa:RelatesTo>
   </soapenv:Header>
   <soapenv:Body>
      _CORRECT_BODY_
   </soapenv:Body>
</soapenv:Envelope>
    <binding name="NinjaBinding">
      <security allowSerializedSigningTokenOnReply="true" enableUnsecuredResponse="true"
      authenticationMode="UserNameOverTransport" requireDerivedKeys="false"
      securityHeaderLayout="Lax" includeTimestamp="false" allowInsecureTransport="true"
      keyEntropyMode="ClientEntropy"
      messageProtectionOrder="SignBeforeEncryptAndEncryptSignature"
    messageSecurityVersion="WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"
      requireSecurityContextCancellation="false">
        <localServiceSettings detectReplays="false" />
        <secureConversationBootstrap _IDENTICAL_TO_ABOVE_
        </secureConversationBootstrap>
      </security>
      <textMessageEncoding />
      <httpsTransport />
    </binding>