WCF是否支持SOAP 1.1的WS-Security?

时间:2011-03-23 22:51:06

标签: c# .net wcf soap ws-security

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

<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>

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

  

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

据我所知,使用wsHttpBinding将导致WCF发送SOAP 1.2请求,而使用basicHttpBinding将导致SOAP 1.1请求。由于WS-Security部分是必需的,据我所知,我必须使用wsHttpBinding。我的问题是如何强制SOAP 1.1请求?我有什么选择?

2 个答案:

答案 0 :(得分:13)

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

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

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

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

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

有关WCF绑定的更详细,非常有用的信息以及如何在配置中“组合”自己的自定义绑定,请阅读Aaron Skonnard撰写的这篇优秀的MSDN文章Service Station: WCF Bindings In Depth

答案 1 :(得分:7)

您必须使用BasicHttpBinding,它还支持TransportWithMessageCredentials(SOAP 1.1 + HTTPS + WS-Security X.509证书令牌配置文件)或根据您的所有需求创建自定义绑定。