kat*_*tit 3 .net c# wcf soap web-services
我正在研究客户端应用程序以利用SOAP Web服务.添加SOAP Web服务作为服务引用.它连接到IBM服务器和服务器需要WS-Security基本身份验证.
使用默认设置调用并收到错误(无身份验证标头)
修改后的代码看起来像这样:
var service = new RealTimeOnlineClient();
service.ClientCredentials.UserName.UserName = "xxxxx";
service.ClientCredentials.UserName.Password = "yyyyy";
Run Code Online (Sandbox Code Playgroud)
现在,当我看到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上快速搜索和一堆答案将我指向微软的HotFix,他们在那里添加了新的属性EnableUnsecuredResponse.问题是 - 我无法弄清楚在我的代码或配置中应用此属性的位置.添加到securityweb.config中的标记不起作用(错误输出找不到属性).
据我所知,.NET 3.5中出现了修补程序,2009 - 2010年出现了大多数问题.它应该在4.5中,对吗?如何将此属性应用于我的代码?
kat*_*tit 10
我不得不添加以下代码来改变"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);
Run Code Online (Sandbox Code Playgroud)