WCF自定义绑定或basichttpbinding

本文关键字:basichttpbinding 绑定 自定义 WCF | 更新日期: 2023-09-27 18:27:34

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

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

我得到了两个URL进行测试,一个使用HTTPS,另一个使用HTTP。生产服务器将使用HTTPS。

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

这是绑定的代码:

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时,它工作得很好。当我尝试使用相同绑定的HTTPS时,我会收到以下错误:

"'CustomBinding'。'http://tempuri.org/'serviceRequestUpdate_PortType'的绑定。'http://schemas.officedepot.com/ODTechServices/serviceRequestUpdate'协定配置的身份验证模式需要传输级别的完整性和机密性。但是,传输不能提供完整性和机密性。"

我还尝试过使用HTTPS的basichttpbinding,如下所示:

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

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

"安全处理器在消息中找不到安全标头。这可能是因为消息是不安全的错误,或者是因为通信方之间的绑定不匹配。如果服务配置为安全性,而客户端没有使用安全性,就会发生这种情况。"

我注意到实际的web服务调用已经发出,操作已经执行。它似乎在收到回复方面存在问题。我还注意到,当我发出请求时,我会传递时间戳,但响应没有时间戳,这可能会导致绑定不匹配。但是如果我使用basicHttpBinding,就没有办法设置IncludeTimestamp = false

WCF自定义绑定或basichttpbinding

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

相关文章:
  • 没有找到相关文章