在.NET 4.5 WCF不安全响应 [英] WCF Unsecured response in .NET 4.5
问题描述
我工作的客户端应用程序使用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?
推荐答案
我不得不添加下面的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);
这篇关于在.NET 4.5 WCF不安全响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!