使用jQuery通过Web服务进行SOAP身份验证

Ati*_*tif 5 jquery soap web-services forms-authentication

我有一个Web服务,需要一个soap标头并返回一个身份验证令牌.我已设法使用jquery将soap标头发布到web服务.问题是如何使浏览器在每个Web服务授权请求上发送经过身份验证的令牌.你的帮助会很大.我使用的有用链接如下:参考:

  1. 使用SOAP保护ASP.Net Web服务

  2. 从Jquery调用Webservice(发布SOAP标头)

码:

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)
    }
Run Code Online (Sandbox Code Playgroud)

Ian*_*ood 0

如果响应提供肯定 - 将该令牌发送回您的服务器以存储在会话中。