使用 jQuery 调用 SOAP WSDL

call soap wsdl using jquery

本文关键字:WSDL SOAP 调用 jQuery 使用      更新时间:2023-09-26

我有一个用java编写并使用axis2server公开的Web服务。我需要使用 jquery 调用该服务。我的 UI 托管在同一台机器上,但位于不同的端口 (8080) 中。我尝试了以下代码

$('#submit').click(function (event) {
    alert("success");
    var soapmessage = "<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope' " + " xmlns:iris='http://iris.ramco.com'>";
    soapmessage += "<soap:Header/>";
    soapmessage += "<soap:Body>";
    soapmessage += "<iris:authenticateUser>";
    soapmessage += "<inputjson>                {username:'admin',password:'admin12*'}</inputjson>";
    soapmessage += "</iris:authenticateUser>";
    soapmessage += "</soap:Body>";
    soapmessage += "</soap:Envelope>";
    alert(soapmessage);
    $.ajax({
        type: 'Post',
        url: 'http://localhost:8090/axis2/services/CiRISService',
        data: soapmessage,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (data) {
            alert(data);
        },
        error: function (data) {
            alert("eror" + data.d);
        }
    });
    alert("Form Submitted");
});

但是我得到未定义的错误。提前谢谢。

为什么不使用 SOAP 客户端库?例如,有一个jQuery插件:http://archive.plugins.jquery.com/project/jqSOAPClient

请记住,如果没有专门的库,您永远不应该直接调用 SOAP 方法。有太多你意想不到的陷阱。

您正在对 SOAP 请求使用内容类型 "application/json; charset=utf-8"(和数据类型 "json")。相反,请尝试这些

contentType: "text/xml; charset=utf-8"

数据类型:"xml"

编辑:我同意谢达尔的观点,使用图书馆。