我正在尝试将WSSE SOAP Header添加到我的服务调用中,但大多数示例都集中在WCF上.我没有使用WCF.我添加了一个Web引用(WSDL).
我尝试了各种方法但没有成功,比如 – 覆盖GetWebRequest方法:
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; }
WSSE安全标题应该类似于:
<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>
提前谢谢了!
亲切的问候,