从 WCF 客户端连接到 WSE 3.0 Web 服务 [英] Connecting to a WSE 3.0 Web Service From a WCF Client

查看:30
本文介绍了从 WCF 客户端连接到 WSE 3.0 Web 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法从 WCF 客户端连接到第 3 方 WSE 3.0 Web 服务.我已经按照这篇知识库文章中的说明实现了自定义绑定类:

I'm having difficulty connecting to a 3rd party WSE 3.0 web service from a WCF client. I have implemented the custom binding class as indicated in this KB article:

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

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

The problem seems to have to do with the security assertion used by the web service - UsernameOverTransport.

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

When I attempt to call a method, I get the following exception:

System.InvalidOperationException:'WseHttpBinding'.'[命名空间]'具有约束力的'MyWebServiceSoap'.'[命名空间]'合同配置了一个需要的认证模式传输级完整性和保密.然而运输不能提供完整性和保密..

System.InvalidOperationException: The 'WseHttpBinding'.'[namespace]' binding for the 'MyWebServiceSoap'.'[namespace]' contract is configured with an authentication mode that requires transport level integrity and confidentiality. However the transport cannot provide integrity and confidentiality..

它需要用户名、密码和 CN 号码.在供应商提供给我们的示例代码中,这些凭据捆绑在 Microsoft.Web.Services3.Security.Tokens.UsernameToken 中.以下是供应商提供的示例:

It is expecting a username, password, and CN number. In the example code supplied to us by the vendor, these credentials are bundled in a Microsoft.Web.Services3.Security.Tokens.UsernameToken. Here's the example supplied by the vendor:

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 客户端的代码片段:


This works fine from a 2.0 app w/ WSE 3.0 installed. Here is a snippet of the code from my WCF client:

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 文章),但我似乎无法克服困难.有人可以帮我吗?

I've scoured the web looking for an answer to this question. Some sources get me close (like the MS KB article), but I can't seem to get over the hump. Can someone help me out?

推荐答案

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

I had success in a similar case with the following binding configuration:

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

希望它也适用于您.

这篇关于从 WCF 客户端连接到 WSE 3.0 Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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