6

我无法从 WCF 客户端连接到第 3 方 WSE 3.0 Web 服务。我已经实现了此知识库文章中所示的自定义绑定类:

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

该问题似乎与 Web 服务使用的安全断言有关 - UsernameOverTransport。

当我尝试调用方法时,出现以下异常:

System.InvalidOperationException:'MyWebServiceSoap'.'[namespace]' 合同的'WseHttpBinding'.'[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 文章),但我似乎无法克服困难。有人可以帮我吗?

4

2 回答 2

10

我使用以下绑定配置在类似情况下取得了成功:

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

希望它也适合你。

于 2011-10-11T06:51:17.103 回答
1

错误消息是指传输级别安全性,这通常意味着 https。

您还没有显示您的配置文件。但我猜您已将安全性配置为传输(或者作为另一种选择的结果需要它)并使用 http 而不是 https 的地址。

于 2009-08-10T12:29:39.570 回答