0

我想从 Webservice(Soap) 获取数据,但没有成功。我的服务在这里http://icafe.ipos.vn/WSUitility/evsServiceUtility.svc?wsdl
我使用 jquery 来请求服务,代码如下

    var soap = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "<soap:Body>" +
        "<Test xmlns=''>" +
        "</Test>" +
        "</soap:Body>" +
        "</soap:Envelope>";
    $.ajax({
        url: 'http://icafe.ipos.vn/WSUitility/evsServiceUtility.svc?wsdl',
        method: 'post',
        data: soap,
        contentType: "text/xml",
        dataType: "xml",
        beforeSend: function (xhr) {
            xhr.setRequestHeader("SOAPAction", "urn:evsServiceUtility/Test1");
        },
        crossDomain: true,
        success: function(SOAPResponse) {
            alert('ok');
        },
        error: function(SOAPResponse) {
            alert('no ok');
        }
    });

我的服务:

    public string Test()
    {
        try
        {
            return "Successfull!";
        }
        catch (Exception ex)
        {
            return ex.Message;
        }
    }

我花了很多时间搜索并尝试了许多解决方案,但它不起作用。
谁能帮我?

4

2 回答 2

0

我看不到您的名为 soap 的变量在哪里使用。看起来它应该是被发送到 SOAP 服务的“数据:”,但是那里有一个叫做 bhRequest 的东西。

还要确保您允许 Phonegap 访问您的远程服务器

<access subdomains="true" origin="*" />

在您的 config.xml 中。当您开始工作时,您可以通过将其限制在您的 icafe.ipos.vn 域中来使其更具限制性。

于 2013-10-16T12:13:39.017 回答
0

我想您的数据类型可以是 XML,这不是问题。问题是,你如何编码你的data或参数?也许在浏览器的控制台中检查 POST 请求中的响应。

我在 c# 中选择了一些东西来自动启用它,这里有很好的记录:http: //encosia.com/3-mistakes-to-avoid-when-using-jquery-with-aspnet-ajax/

然后剩下的一件事就是JSON.stringify()数据。那么bhRequestjson对象对吗?

...然后跨浏览器,您必须实现 json2.js: https ://github.com/douglascrockford/JSON-js

于 2013-10-16T10:32:30.983 回答