我有一个 Web 服务,需要一个 SOAP 头并返回一个身份验证 token 。我已经设法使用 jquery 将 SOAP 头发布到网络服务。问题是如何让浏览器在每个通过 Web 服务进行授权的请求上发送经过身份验证的 token 。我们将非常感谢您的帮助。我使用的有用链接如下: 引用:
代码:
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)
}
请您参考如下方法:
如果响应提供肯定 - 将该 token 发送回您的服务器以存储在 session 中。
