当尝试使用 jQuery AJAX 调用 SOAP Web 服务时,为什么请求正文为空?

发布于 2024-12-20 09:40:40 字数 732 浏览 0 评论 0原文

我已经构建了一个完整的肥皂信封 soapEnvelopeXML 并且我可以看到通过我的 TCP/IP 监视器进行的调用,但问题是请求 URI 不是调用正确的方法,而是与 < code>soapEnvelopeXML 就好像它是标头中的一个选项。所以我没有得到任何结果。我不想将参数作为 JSON 对象传递。关于我可能出错的地方有什么想法吗?

$.ajax({
    type: "GET",
    url: "http://localhost:8080/webservice/serviceName/",
    data: soapEnvelopeXML,
    contentType: "text/xml",
    dataType: "xml",       
    error: function(xhr, status, error) { 
        alert("Error processing your request: \n" + status + " : " + error);
    },
    success: function(response){
        var xml = $(response);
        alert(xml);
    }
});

我已经测试了上面的代码以使用 POST 而不是 GET,但我得到了一个空响应,并且我看到正在进行一个空的 Web 服务调用。我不知道 GET 对于 SOAP 请求来说是非法的。有谁知道为什么发送的内容是空的呼叫?

I have constructed a full soap envelope soapEnvelopeXML and I can see the call come through my TCP/IP Monitor, but the issue is that instead of calling the right method, the request URI comes in concatenated with the soapEnvelopeXML as if it is an option in the header. So i am not getting any result. I don't want to pass in the parameters as JSON objects. Any ideas on where i could be going wrong?

$.ajax({
    type: "GET",
    url: "http://localhost:8080/webservice/serviceName/",
    data: soapEnvelopeXML,
    contentType: "text/xml",
    dataType: "xml",       
    error: function(xhr, status, error) { 
        alert("Error processing your request: \n" + status + " : " + error);
    },
    success: function(response){
        var xml = $(response);
        alert(xml);
    }
});

I have tested the code on top to use POST instead of GET but I was getting an empty response and I see that an empty webservice call was being made. I didnt know that GET was illegal for SOAP requests. Does anyone know why the sent content is an empty call?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

心作怪 2024-12-27 09:40:40

也许问题在于 SOAP 应该是 POST?

http://www.coderanch.com/ t/463869/Web-Services/java/SOAP-request-as-HTTP

问:如何以 HTTP GET 方式发送 SOAP 请求?

答:你不能。 SOAP 始终使用 POST。只有 REST 使用 GET(以及各种其他 HTTP 方法,包括 POST)。

更新:

谢谢,我使用 GET 是因为当我使用 POST 时进行了空的 Web 服务调用。那么关于为什么我在使用 POST 时进行空 Web 服务调用有什么想法吗?

如果我转到本地主机,我在本地机器上会得到相同的行为,但我通过这样做来使其工作:

  1. 创建一个域名
  2. 将其粘贴在主机文件中,指向127.0 .0.1
  3. 使用该假域名访问本地网络服务器

尝试此代码,它对我有用:

var soapEnvelopeXML= "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"> <soap:Header>CUSTOM HEADER</soap:Header> <soap:Body>PARAMS</soap:Body> </soap:Envelope>";
$.ajax({
    type: "post",
    url: "http://superblah.com/webservice/serviceName/",
    contentType: "text/xml; charset=\"utf-8\"",
    dataType: "xml",       
    data: soapEnvelopeXML,
    processData: false,
    beforeSend: function(xhr){
      xhr.setRequestHeader(
        "SOAPTarget",
        "http://superblah.com/webservice/serviceName/"
      );
      xhr.setRequestHeader(
        "SOAPAction",
        "http://superblah.com/webservice/serviceName/Something"
      );
    },
    error: function(xhr, status, error) { 
        alert("Error processing your request: \n" + status + " : " + error);
    },
    success: function(response){
        var xml = $(response);
        alert(xml);
    }
});

我从这里获得了此代码:

Maybe the problem is that SOAP should be POST?

http://www.coderanch.com/t/463869/Web-Services/java/SOAP-request-as-HTTP

Q: How do I send a SOAP request as HTTP GET?

A: You can't. SOAP always uses POST. Only REST uses GET (as well as various other HTTP methods, including POST).

Update:

Thanks for this, I was using GET because an empty web-service call was was made when I use POST. So any ideas as to why I make empty web-service calls when I use POST?

I am getting the same behavior on my local box if I go to localhost, but I got it working by doing this:

  1. Make up a domain name
  2. Stick it in the hosts file, pointing to 127.0.0.1
  3. Access the local webserver with that fake domain

Try this code, it is working for me:

var soapEnvelopeXML= "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\"> <soap:Header>CUSTOM HEADER</soap:Header> <soap:Body>PARAMS</soap:Body> </soap:Envelope>";
$.ajax({
    type: "post",
    url: "http://superblah.com/webservice/serviceName/",
    contentType: "text/xml; charset=\"utf-8\"",
    dataType: "xml",       
    data: soapEnvelopeXML,
    processData: false,
    beforeSend: function(xhr){
      xhr.setRequestHeader(
        "SOAPTarget",
        "http://superblah.com/webservice/serviceName/"
      );
      xhr.setRequestHeader(
        "SOAPAction",
        "http://superblah.com/webservice/serviceName/Something"
      );
    },
    error: function(xhr, status, error) { 
        alert("Error processing your request: \n" + status + " : " + error);
    },
    success: function(response){
        var xml = $(response);
        alert(xml);
    }
});

I got this code from here:

耳钉梦 2024-12-27 09:40:40

它与 URL 连接的原因是 GET 方法的含义。
将其更改为 POST,我怀疑它对您有用。

The reason it is concatenated with the URL is that is what the GET method means.
Change this to POST and I suspect it will work for you.

罪#恶を代价 2024-12-27 09:40:40
$.ajax({
    type: "POST",
    url: "http://localhost:8080/webservice/serviceName/",
    data: soapEnvelopeXML,
    contentType: "text/xml",
    dataType: ($.browser.msie) ? "text" : "xml",       
    error: function(xhr, status, error) { 
        alert("Error processing your request: \n" + status + " : " + error);
    },
    success: function(response){
        var xml = $(response);
        alert(xml);
    }
});

$.ajax({
    type: "POST",
    url: "http://localhost:8080/webservice/serviceName/",
    data: soapEnvelopeXML,
    contentType: "text/xml",
    dataType: ($.browser.msie) ? "text" : "xml",       
    error: function(xhr, status, error) { 
        alert("Error processing your request: \n" + status + " : " + error);
    },
    success: function(response){
        var xml = $(response);
        alert(xml);
    }
});

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文