gpt4 book ai didi

c# - WCF 自定义绑定(bind)或 basichttpbinding

转载 作者:太空宇宙 更新时间:2023-11-03 10:59:25 24 4
gpt4 key购买 nike

我正在尝试实现 WCF 客户端。服务器需要 WSSE header 。

我能够让它与 HTTP 一起工作。但是它不适用于 HTTPS。

我得到了 2 个 URL 用于测试,一个使用 HTTPS,一个使用 HTTP。生产服务器将使用 HTTPS。

我正在使用 CustomBinding 使其与 HTTP 一起工作

绑定(bind)代码如下:

var securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();
securityElement.EnableUnsecuredResponse = true;
securityElement.MessageSecurityVersion = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;
var encodingElement = new TextMessageEncodingBindingElement(MessageVersion.Soap11, Encoding.UTF8);
var transportElement = new HttpTransportBindingElement();
var binding = new CustomBinding(securityElement, encodingElement, transportElement);
return binding;

当我使用 HTTP URL 时效果很好。当我尝试使用相同绑定(bind)的 HTTPS 时,出现此错误:

“'CustomBinding'。' http://tempuri.org/ '绑定(bind)'serviceRequestUpdate_PortType'。 http://schemas.officedepot.com/ODTechServices/serviceRequestUpdate '契约(Contract)配置了需要传输级别完整性和 secret 性的身份验证模式。但是传输无法提供完整性和 secret 性。"

我也试过为 HTTPS 使用 basichttpbinding,如下所示:

var binding = new BasicHttpBinding(BasicHttpSecurityMode.TransportWithMessageCredential);
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
return binding;

现在在这种情况下,我遇到以下错误:

“安全处理器无法在消息中找到安全 header 。这可能是因为消息是不安全的错误,或者是因为通信双方之间的绑定(bind)不匹配。如果服务配置为安全并且客户端没有使用安全性。”

我注意到进行了实际的 Web 服务调用并执行了操作。它似乎在接收响应方面有问题。我还注意到,当我发出请求时,我正在传递时间戳,但响应没有时间戳,这可能导致绑定(bind)不匹配。但是,如果我使用 basicHttpBinding,则无法设置 IncludeTimestamp = false

最佳答案

我得到了答案只需要更改 var transportElement = new HttpTransportBindingElement();到 var transportElement = new HttpsTransportBindingElement();并使用自定义绑定(bind)

关于c# - WCF 自定义绑定(bind)或 basichttpbinding,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18230462/

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