gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:27:47 26 4
gpt4 key购买 nike

我在从 WCF 客户端连接到第三方 WSE 3.0 Web 服务时遇到困难。我已经实现了此知识库文章中所示的自定义绑定(bind)类:

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

最佳答案

我使用以下绑定(bind)配置在类似的案例中取得了成功:

<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 - 从 WCF 客户端连接到 WSE 3.0 Web 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1246689/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com