fli*_*erg 7 .net c# wcf soap visual-studio-2010
在项目中使用WCF和C#时,我得到一个异常MesssageSecurityException,消息"Security header为空".以下是响应(根据MS Service Trace Viewer):
<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 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" soapenv:mustUnderstand="true"></wsse:Security>
<wsa:Action>_WHAT_I_DID_</wsa:Action>
<wsa:RelatesTo>_MSG_ID_OF_REQUEST_</wsa:RelatesTo>
</soapenv:Header>
<soapenv:Body>
_CORRECT_BODY_
</soapenv:Body>
</soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)
实际上,安全标头是"空的",但据我所知,它仍然正确地适应安全标头定义.
我也尝试过编辑绑定,但这似乎也没有帮助.我也发现了一个类似的问题,启用EnableUnsecuredResponse会有所帮助,但它不在这里.
以下是SoapUI的回复:
<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>
Run Code Online (Sandbox Code Playgroud)
除了关闭安全标头之外,它们几乎完全相同.哪个有趣,但不应该提出例外?
我还发现了一个类似的问题,其中解决方案是创建一个自定义消息编码器并剥离整个安全标头,尽管这将是一个额外不需要的步骤.这是用.Net和WCF做的唯一方法吗?没有内容,WCF不能处理安全头吗?
编辑:澄清问题,是编写一个编码器,它丢弃安全头是使用WCF接收和解析带有空安全头的SOAP消息的唯一方法吗?
EDIT2:添加conf的一部分:
<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>
Run Code Online (Sandbox Code Playgroud)
据我所知,它的配置允许几乎所有东西?
(现在我正在回答我自己的问题,因为我已经能够得出某种答案)
简而言之,您不能将 WCF “开箱即用”(即通过 *.config)与在响应中提供空安全标头的应用程序服务器一起使用。您必须实现一个编码器,将消息修改为 WCF 框架可接受的格式。
有关更多信息,请阅读此博客,其中包含编码器及其应用程序的相当好的演练。这个博客(另一个博客)还提供了一个能够解决我的问题的代码片段,即修改安全标头。
我想知道为什么 MS 和 Oracle 产品永远不能和平共处:D