微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从WCF客户端连接到WSE 3.0 Web服务

我很难从WCF客户端连接到第三方WSE 3.0 Web服务.我已经实现了这个知识库文章中指出的自定义绑定类:

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

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

当我尝试调用方法时,我得到以下异常:

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中.以下是供应商提供的示例:

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://www.jb51.cc/html/242543.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐