WCF 是否支持 SOAP 1.1 的 WS-Security? [英] Does WCF support WS-Security with SOAP 1.1?

查看:28
本文介绍了WCF 是否支持 SOAP 1.1 的 WS-Security?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用一些需要 WS-Security 的第三个 Web 服务.我使用以下配置创建了一个 WCF 端点:

I need to call some 3rd Web services that require WS-Security. I created a WCF endpoint with the following configuration:

<system.serviceModel>
  <bindings>
    <wsHttpBinding>
      <binding name="TestBinding">
        <security mode="TransportWithMessageCredential">
          <message clientCredentialType="Certificate" />
        </security>
      </binding>
    </wsHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="TestBehavior">
        <callbackDebug includeExceptionDetailInFaults="true" />
        <clientCredentials>
          <clientCertificate findValue="Acme" storeLocation="CurrentUser" storeName="My" x509FindType="FindBySubjectName" />
          <serviceCertificate>
            <authentication certificateValidationMode="PeerOrChainTrust" />
          </serviceCertificate>
        </clientCredentials>
      </behavior>
    </endpointBehaviors>
  </behaviors>
  <client>
    <endpoint address="https://acme.com/webservices" binding="wsHttpBinding" bindingConfiguration="TestBinding" behaviorConfiguration="TestBehavior" contract="AcmeContract" name="AcmeEndpoint"></endpoint>
  </client>
</system.serviceModel>

问题是第 3 方服务器抛出以下异常:

The problem is that the 3rd party servers a throwing the following exception:

收到的协议'_http://schemas.xmlsoap.org/wsdl/soap12/',所需协议'_http://schemas.xmlsoap.org/wsdl/soap/'.

Received protocol '_http://schemas.xmlsoap.org/wsdl/soap12/', required protocol '_http://schemas.xmlsoap.org/wsdl/soap/'.

我知道使用 wsHttpBinding 将导致 WCF 发送 SOAP 1.2 请求,而使用 basicHttpBinding 将导致 SOAP 1.1 请求.由于需要 WS-Security 部分,据我了解,我必须使用 wsHttpBinding.我的问题是如何强制执行 SOAP 1.1 请求?我有哪些选择?

I understand that using the wsHttpBinding will cause WCF to send a SOAP 1.2 request while using the basicHttpBinding will result in a SOAP 1.1 request. Since the WS-Security parts are required, as I understand it, I have to use the wsHttpBinding. My question is how do I force a SOAP 1.1 request? What are my options?

推荐答案

为了使用 WS-Addressing (wsHttpBinding),但使用 SOAP 1.1(SOAP 1.2 是默认值),您需要定义自定义 WCF 绑定(例如在配置中)并使用它:

In order to use WS-Addressing (wsHttpBinding), but with SOAP 1.1 (SOAP 1.2 being the default), you need to define a custom WCF binding (e.g. in config) and use that:

<bindings>
   <customBinding>
      <binding name="WsHttpSoap11" >
         <textMessageEncoding messageVersion="Soap11WSAddressing10" />
         <httpTransport/>
      </binding>
   </customBinding>
</bindings>

然后在您的端点定义中,使用:

and then in your endpoint definition, use:

<endpoint name="WsSoap11"
    address="....."
    binding="customBinding"
    bindingConfiguration="wsHttpSoap11"
    contract="....." />

当然,您可以使用其他属性扩展上面定义的自定义绑定,例如 或其他.

Of course, you can extend the custom binding defined above with additional properties, e.g. <reliableMessaging> or others.

有关 WCF 绑定以及如何在配置中组合"您自己的自定义绑定的更详细、非常有用的信息,请阅读这篇优秀的 MSDN 文章 服务站:WCF 深度绑定 作者:Aaron Skonnard.

For more very detailed, very useful info on WCF bindings and how to "compose" your own custom bindings in config, read this excellent MSDN article Service Station: WCF Bindings In Depth by Aaron Skonnard.

这篇关于WCF 是否支持 SOAP 1.1 的 WS-Security?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆