【发布时间】:2019-06-12 15:04:12
【问题描述】:
我使用了一个 WebReference 并且接收服务器需要一个 WS-Security 标头:
<wsse:UsernameToken wsu:Id="Example">
<wsse:Username> ... </wsse:Username>
<wsse:Password Type="..."> ... </wsse:Password>
<wsse:Nonce EncodingType="..."> ... </wsse:Nonce>
<wsu:Created> ... </wsu:Created>
</wsse:UsernameToken>
我假设这将包含在 WSDL 中,但是在阅读 this post 之后,我明白逻辑应该分开。
我用来执行请求的客户端类包含一个代理属性IWebProxy:HttpWebClientProtocol。我相信这是我应该提供标题/覆盖信息的地方。请问有人可以确认一下吗?
我也有一些代码可以生成正确的标头。但是我不确定如何在不修改WebReference 的情况下指定这些标题/元素。
public static Tuple<EndpointAddress, BindingElementCollection, string, string> PrepareGlowsAuth(string endpoint)
{
EndpointAddress soapEndpoint = new EndpointAddress(string.Format("{0}/{1}", (IsProduction ? productionBaseUrl : testingBaseUrl), endpoint));
BasicHttpsBinding binding = new BasicHttpsBinding();
binding.Security.Mode = BasicHttpsSecurityMode.TransportWithMessageCredential;
binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
BindingElementCollection elements = binding.CreateBindingElements();
elements.Find<SecurityBindingElement>().EnableUnsecuredResponse = true;
return new Tuple<EndpointAddress, BindingElementCollection, string, string>(soapEndpoint, elements, "username", "password");
}
如果有人能指出我正确的方向,将不胜感激!
更新:按照建议后,我看不到 Client 或 Response 类。
【问题讨论】:
-
你看过这个s/o帖子吗? stackoverflow.com/questions/23663007/…
标签: c# ws-security soapheader