2011-03-23 93 views
9

我需要調用一些需要WS-Security的第三個Web服務。我創建了一個WCF端點配置如下:WCF是否支持帶有SOAP 1.1的WS-Security?

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

的問題是,第三方服務器中拋出以下異常:

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

據我所知,使用的wsHttpBinding將導致WCF發送使用basicHttpBinding時的SOAP 1.2請求將導致SOAP 1.1請求。由於WS-Security部分是必需的,據我所知,我必須使用wsHttpBinding。我的問題是如何強制一個SOAP 1.1請求?我有什麼選擇?

回答

7

您必須使用也支持TransportWithMessageCredentials(SOAP 1.1 + HTTPS + WS-Security X.509證書令牌配置文件)的BasicHttpBinding或根據您的所有需求創建自定義綁定。

+0

我試過將wsHttpBinding更改爲basicHttpBinding,但它會導致異常並且不會將其發送給第三方服務器。從我讀到的,basicHttpBinding與證書認證不兼容。我錯了嗎? – 2011-03-23 23:02:14

+0

MSDN表示支持證書認證:http://msdn.microsoft.com/en-us/library/system.servicemodel.basichttpmessagecredentialtype.aspx – 2011-03-23 23:33:11

12

爲了使用的WS-Addressing(wsHttpBinding),但與SOAP 1.1(SOAP 1.2是默認值),你需要定義一個自定義的WCF結合(如配置)和使用:

<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

這剛剛幫助我創建了一個使用SOAP1.2和2004年8月的端點WS-Addressing的。填補了最終的小差距,使它點擊我! – squillman 2013-04-16 21:07:27

+0

這個答案正是我需要修復錯誤:(415)無法處理消息,因爲內容類型'text/xml; charset = utf-8'不是預期的類型'application/soap + xml;字符集= UTF-8' 。 – 2013-10-11 04:44:25

+0

-1:這不適用於HTTPS地址,因爲自定義綁定中使用的傳輸是用於HTTP的。 – reSPAWNed 2014-08-15 11:24:16

相關問題