【发布时间】:2011-07-05 06:31:52
【问题描述】:
我有一个需要soap 标头并返回身份验证令牌的Web 服务。我已经设法使用 jquery 将肥皂标头发布到 web 服务。问题是我如何让浏览器在每个请求通过 Web 服务进行授权时发送经过身份验证的令牌。您的帮助将不胜感激。我使用的有用链接如下: 参考:
代码:
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)
}
【问题讨论】:
标签: jquery web-services soap forms-authentication