AJAX调用SOAP远程Web服务?

时间:2016-03-09 13:02:23

标签: javascript ajax soap web service

我正在尝试使用AJAX调用连接到SOAP Web服务。

这是我的代码:

<script>
        var webServiceURL = "http://some.ip.address/NameOfService.svc";
        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>'+
                '<GetName>'+
                '<UserId>' +319+ '</UserId>'+
                '</GetName>'+
                '</soap:Body>'+
                '</soap:Envelope>';

        $("#btn").click(function(){
            jQuery.support.cors = true;
            $.ajax({
                url: webServiceURL,
                type: "POST",
                dataType: "xml",
                contentType: "text/xml; charset='utf-8'",
                headers: {
                    SOAPAction: "http://some.ip.address/NameOfService.svc/GetName"
                },
                data: soapMessage,
                success: function(soapResponse){
                    $('#test').html(soapResponse);
                }
            });
        });
    </script>

不幸的是,我在浏览器控制台上收到404错误。请帮忙吗?

更新:

我尝试了不同的方法,使用此插件:http://plugins.jquery.com/soap/

我的代码是:

<script>
        $.soap({
            url: 'http://some.ip/NameOfService.svc?wsdl',
            method: 'GetName',
            data: {
                userId: 389
            },

            success: function (soapResponse) {
                // do stuff with soapResponse
                // if you want to have the response as JSON use soapResponse.toJSON();
                // or soapResponse.toString() to get XML string
                // or soapResponse.toXML() to get XML DOM
                console.log(soapResponse)
            },
            error: function (soapResponse) {
                // show error
                console.log(soapResponse)
            }
        });
    </script>

我再次收到错误:XMLHttpRequest无法加载服务。预检的响应具有无效的HTTP状态代码404。

0 个答案:

没有答案