簡體   English   中英

從WCF客戶端連接到WSE 3.0 Web服務

[英]Connecting to a WSE 3.0 Web Service From a WCF Client

我很難從WCF客戶端連接到第三方WSE 3.0 Web服務。 我已經實現了這個知識庫文章中指出的自定義綁定類:

http://msdn.microsoft.com/en-us/library/ms734745.aspx

該問題似乎與Web服務使用的安全斷言有關 - UsernameOverTransport。

當我嘗試調用方法時,我得到以下異常:

System.InvalidOperationException:'WseHttpBinding'。'[namespace]'綁定'MyWebServiceSoap'。'[namespace]'契約配置了一種需要傳輸級別完整性和機密性的身份驗證模式。 但運輸不能提供完整性和保密性。

它需要用戶名,密碼和CN號。 在供應商提供給我們的示例代碼中,這些憑據捆綁在Microsoft.Web.Services3.Security.Tokens.UsernameToken中。 以下是供應商提供的示例:

MyWebServiceWse proxy = new MyWebServiceWse();

UsernameToken token = new UsernameToken("Username", "password", PasswordOption.SendPlainText);

token.Id = "<supplied CN Number>";

proxy.SetClientCredential(token);

proxy.SetPolicy(new Policy(new UsernameOverTransportAssertion(), new RequireActionHeaderAssertion()));

MyObject mo = proxy.MyMethod();

這適用於安裝了WSE 3.0的2.0應用程序。 以下是我的WCF客戶端的代碼片段:

EndpointAddress address = new EndpointAddress(new Uri("<web service uri here>"));

WseHttpBinding binding = new WseHttpBinding(); // This is the custom binding I created per the MS KB article

binding.SecurityAssertion = WseSecurityAssertion.UsernameOverTransport;
binding.EstablishSecurityContext = false;

// Not sure about the value of either of these next two
binding.RequireDerivedKeys = true;
binding.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncrypt;

MembershipServiceSoapClient proxy = new MembershipServiceSoapClient(binding, address);

// This is where I believe the problem lies – I can’t seem to properly setup the security credentials the web service is expecting 

proxy.ClientCredentials.UserName.UserName = "username";
proxy.ClientCredentials.UserName.Password = "pwd";
// How do I supply the CN number?                      

MyObject mo = proxy.MyMethod(); // this throws the exception

我在網上搜索這個問題的答案。 一些消息來源讓我接近(如MS KB文章),但我似乎無法克服困難。 有人可以幫我嗎?

我在以下綁定配置的類似情況下取得了成功:

<bindings>
   <customBinding>
      <binding name="FNCEWS40MTOMBinding">
         <security enableUnsecuredResponse="true" authenticationMode="UserNameOverTransport"
                   allowInsecureTransport="true" messageProtectionOrder="SignBeforeEncrypt">
            <secureConversationBootstrap />
         </security>
         <mtomMessageEncoding messageVersion="Soap12WSAddressingAugust2004"
                              maxBufferSize="2147483647" />
         <httpTransport maxReceivedMessageSize="2147483647" />
     </binding>
  </customBinding>
</bindings>

希望它也適合你。

錯誤消息是指傳輸級別安全性,這通常表示https。

您尚未顯示配置文件。 但我猜你已經將安全配置為傳輸(或者需要作為另一種選擇的后果)並使用了http而不是https的地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM