WCF Unsecured response in .NET 4.5

.net, c#, soap, wcf, web-services

Solution

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);

Problem

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) 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. However, I get exception from 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`. 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). 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?

Original source