简体   繁体   English

WCF在.NET 4.5中的不安全响应

[英]WCF Unsecured response in .NET 4.5

I'm working on client application to utilize SOAP web service. 我正在研究客户端应用程序以利用SOAP Web服务。 Added SOAP web services as Service reference. 添加SOAP Web服务作为服务引用。 It connects to IBM server and server requires WS-Security basic authentification. 它连接到IBM服务器和服务器需要WS-Security基本身份验证。

Called with default settings and got an error(no authentication header) 使用默认设置调用并收到错误(无身份验证标头)

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. 现在,当我看到Fiddler中的响应 - 工作正常(我从服务器得到预期的信封)时,我得到了适当的信封。

However, I get exception from WCF: 但是,我从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.

Quick search and bunch of answers here on SO points me to HotFix from Microsoft where they added new property EnableUnsecuredResponse . 在SO上快速搜索和一堆答案将我指向Microsoft的HotFix,他们在这里添加了新属性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). 在web.config中添加security标记不起作用(错误输出找不到属性)。

I understand hotfix came out for .NET 3.5 and most questions from 2009-2010. 据我所知,.NET 3.5中出现了修补程序,2009 - 2010年出现了大多数问题。 It should be in 4.5 already, correct? 它应该在4.5中,对吗? How do I apply this property to my code? 如何将此属性应用于我的代码?

I had to add following code to alter value of "EnableUnsecureResponse" 我不得不添加以下代码来改变“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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM