我正在尝试将 WSSE SOAP 标头添加到我的服务调用中,但大多数示例都集中在 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>
提前谢谢了!亲切的问候,