【问题标题】:WCF Unsecured response in .NET 4.5.NET 4.5 中的 WCF 不安全响应
【发布时间】:2014-02-11 20:49:03
【问题描述】:

我正在开发客户端应用程序以利用 SOAP Web 服务。添加了 SOAP Web 服务作为服务参考。它连接到 IBM 服务器,服务器需要 WS-Security 基本身份验证。

使用默认设置调用并收到错误(无身份验证标头)

修改后的代码如下:

    var service = new RealTimeOnlineClient();
    service.ClientCredentials.UserName.UserName = "xxxxx";
    service.ClientCredentials.UserName.Password = "yyyyy";

现在,当我在 Fiddler 中查看响应时 - 工作正常(我从服务器收到预期的信封),我得到了正确的信封。

但是,我从 WCF 得到异常:

Security processor was unable to find a security header in the message. This might be because the message is an unsecured fault or because there is a binding mismatch between the communicating parties. This can occur if the service is configured for security and the client is not using security.

SO 上的快速搜索和一堆答案将我指向 Microsoft 的 HotFix,他们在其中添加了新属性 EnableUnsecuredResponse。问题是 - 我无法弄清楚在我的代码或配置中应用此属性的位置。在 web.config 中添加 security 标记不起作用(错误输出找不到属性)。

我了解针对 .NET 3.5 和 2009-2010 年的大多数问题的修补程序。它应该已经在 4.5 中,对吗?如何将此属性应用于我的代码?

【问题讨论】:

  • 你为什么不把这个添加到你的配置文件<security mode="TransportWithMessageCredential" enableUnsecuredResponse="true">

标签: c# .net wcf web-services soap


【解决方案1】:

我必须添加以下代码来更改“EnableUnsecureResponse”的值

var service = new RealTimeOnlineClient();
service.ClientCredentials.UserName.UserName = "xxxxx";
service.ClientCredentials.UserName.Password = "yyyyy";

var elements = service.Endpoint.Binding.CreateBindingElements();
elements.Find<SecurityBindingElement>().EnableUnsecuredResponse = true;
service.Endpoint.Binding = new CustomBinding(elements);

【讨论】:

  • 您有没有找到通过配置文件声明此设置管理的方法?
猜你喜欢
  • 2015-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多