【问题标题】:WCF Custom Binding or basichttpbindingWCF 自定义绑定或基本httpbinding
【发布时间】:2013-08-14 11:26:29
【问题描述】:

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

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

我得到了 2 个用于测试的 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

【问题讨论】:

  • 我得到了答案 只需要更改 var transportElement = new HttpTransportBindingElement();到 var transportElement = new HttpsTransportBindingElement();并使用自定义绑定。
  • 这个问题似乎是题外话,因为用户得到了他的答案
  • @Ravi - 得到答案会使问题脱离主题?
  • @Tim Nope。但用户已经得到了他的答案。所以。如果需要可以重新打开关闭投票:) 没有问题
  • 也许 OP 应该回答他自己的问题而不是评论它。

标签: c# .net wcf web-services


【解决方案1】:

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

【讨论】:

  • 您也可以将此标记为答案,以便人们知道它对您有用。
  • 这对我来说是多么棒的 PITA 调试……感谢自定义绑定以允许 EnableUnsecuredResponse 设置……
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-05
  • 2010-11-29
  • 2019-11-21
  • 1970-01-01
相关资源
最近更新 更多