我正在尝试将WSSE SOAP Header添加到我的服务调用中,但大多数示例都集中在WCF上.我没有使用WCF.我添加了一个Web引用(WSDL).
我尝试了各种方法但没有成功,比如 – 覆盖GetWebRequest方法:@H_301_3@
protected override System.Net.WebRequest GetWebRequest(Uri uri) { string user = "username"; string pwd = "password"; System.Net.WebRequest request = base.GetWebRequest(uri); string auth = string.Format("Basic {0}",Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(string.Format("{0}:{1}",user,pwd)))); request.PreAuthenticate = true; request.AuthenticationLevel = System.Net.Security.AuthenticationLevel.MutualAuthRequested; request.Headers.Add(HttpRequestHeader.Authorization,auth); return request; }
<Security xmlns="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> <UsernameToken> <Username>username</Username> <Password>password</Password> </UsernameToken> </Security>
提前谢谢了!
亲切的问候,@H_301_3@
解决方法
请参考以下内容:
http://underthehood.ironworks.com/2010/01/why-doesnt-my-generated-proxy-class-build-wsse-elements-into-the-soap-request-header.html@H_301_3@
Why doesn’t my generated proxy class build WSSE elements into the SOAP request header?@H_301_3@
How to add security header to a SOAP message?@H_301_3@
哪个提供答案!@H_301_3@