• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在.NET 4.5 WCF不安全响应

用户头像
it1352
帮助1

问题说明

我工作的客户端应用程序使用SOAP的Web服务。新增SOAP Web服务作为服务的参考。它连接到IBM服务器和服务器需要WS-Security的基本认证方式。

I'm working on client application to utilize SOAP web service. Added SOAP web services as Service reference. It connects to IBM server and server requires WS-Security basic authentification.

调用方式的默认设置,并得到了一个错误(无认证头)

Called with default settings and got an error(no authentication header)

修改code看起来像这样:

Modified code to look like so:

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

现在,当我看着响应提琴手 - 工作正常(我从服务器获得预期的信封),我得到了正确的信封背面

Now when I look at response in Fiddler - works properly (I get expected envelope from server), I get proper envelope back.

不过,我从WCF异常:

However, I get exception from WCF:

安全处理器无法找到消息中的安全标头。这可能是因为消息是不安全的故障或因为通信双方之间具有约束力的不匹配。如果服务被配置为安全和客户端不使用安全性可以发生这种情况。

快速搜索和一堆这里答案那么点我从微软那里他们增加了新的属性,以修补程序 EnableUnsecuredResponse 。问题是 - 我想不出哪里该属性适用于我的code或配置。添加到web.config文件中的安全标签不起作用(错误出来找不到属性)。

Quick search and bunch of answers here on SO points me to HotFix from Microsoft where they added new property EnableUnsecuredResponse. Problem is - I can't figure out WHERE to apply this property in my code OR in config. Adding to security tag in web.config doesn't work (errors out can't find property).

据我所知修复出来的.NET 3.5和2009-2010大多数问题。它应该是在4.5已,是否正确?这个属性我该如何申请到我的code?

I understand hotfix came out for .NET 3.5 and most questions from 2009-2010. It should be in 4.5 already, correct? How do I apply this property to my code?

正确答案

#1

我不得不添加下面的code,以改变EnableUnsecureResponse

I had to add following code to alter value of "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);

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcfhcjh
系列文章
更多 icon
同类精品
更多 icon
继续加载