我有一个Web服务,需要一个Soap标头并返回认证令牌。我设法使用jquery将soap标头发布到了Web服务。问题是我如何使浏览器根据Web服务上的每个授权请求发送经过身份验证的令牌。您的帮助将非常有用。我使用的有用链接如下:
参考:
Securing ASP.Net Web Service using SOAP
Calling Webservice from Jquery (Posting SOAP Header)
码:
function logIn(username, password, token) {
var soapMessage =
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> \
<soap:Body> \
<SecuredWebServiceHeader xmlns="http://tempuri.org/"> \
<Username>' + username + '</Username> \
<Password>' + password + '</Password> \
<AuthenticatedToken>' + token + '</AuthenticatedToken> \
</SecuredWebServiceHeader> \
</soap:Body> \
</soap:Envelope>';
$.ajax({
url: "http://localhost/wstest/Service.asmx/AuthenticateUser",
type: "POST",
dataType: "xml",
data: soapMessage,
complete: endLogin,
contentType: "text/xml; charset=\"utf-8\""
});
return false;
}
function endLogin(xmlHttpRequest, status) {
alert(xmlHttpRequest.responseXML)
}
最佳答案
如果响应是肯定的-将令牌发送回服务器以存储在会话中。