简体   繁体   English

使用Ext.Ajax.request调用需要WS Reliable Messaging的跨域Web服务

[英]Using Ext.Ajax.request to call cross-domain web service that requires WS Reliable Messaging

We currently have a javascript client successfully accessing a web service on another domain using something similar to the following code: 当前,我们有一个javascript客户端使用类似于以下代码的内容成功访问了另一个域上的Web服务:

var postXml = "" +

    "<aaa:getSomething>" +
        "<param1>" + obj.param1 + "</param1>" +
        "<param2>" + obj.param2 + "</param2>" +
    "</aaa:getSomething>";

    var data = this.createEnvelope(postXml);
    var request = Ext.Ajax.request({
        url : this.webServiceUrl,
        method : "POST",
        callback : this.onGetSomething,
        obj : obj,
        scope : this,
        headers : {
            SOAPAction: "urn:onGetSomething"
        },
        xmlData : data
    });

We are being required to add WS-ReliableMessaging to our web service. 我们需要将WS-ReliableMessaging添加到我们的Web服务中。 Is there a way to modify our javascript client to connect to the new WS-ReliableMessaging-enabled service? 有没有一种方法可以修改我们的javascript客户端以连接到启用了WS-ReliableMessaging的新服务? I'm not very Javascript-savvy, but from my research so far I suspect the only way might be to make the Ajax request to a local server-side proxy JSP that makes the call from Java, is this the case? 我不是很精通Java语言,但是到目前为止,我一直怀疑我的唯一方法可能是向从Java进行调用的本地服务器端代理JSP发出Ajax请求。

You should JSON-P for cross-domain access, if you check the Ajax documentation here: http://docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.proxy.Ajax , the limitations section says: 如果您在此处查看Ajax文档,则应该使用JSON-P进行跨域访问: http : //docs.sencha.com/extjs/5.1/5.1.0-apidocs/#!/api/Ext.data.proxy。 Ajax的“限制”部分显示:

"AjaxProxy cannot be used to retrieve data from other domains. If your application is running on http://domainA.com it cannot load data from http://domainB.com because browsers have a built-in security policy that prohibits domains talking to each other via AJAX. “ AjaxProxy无法用于从其他域中检索数据。如果您的应用程序在http://domainA.com上运行,则它无法从http://domainB.com加载数据,因为浏览器具有内置的安全策略,禁止域通信通过AJAX彼此。

If you need to read data from another domain and can't set up a proxy server (some software that runs on your own domain's web server and transparently forwards requests to http://domainB.com , making it look like they actually came from http://domainA.com ), you can use Ext.data.proxy.JsonP and a technique known as JSON-P (JSON with Padding), which can help you get around the problem so long as the server on http://domainB.com is set up to support JSON-P responses. 如果您需要从另一个域读取数据并且不能设置代理服务器(某些软件可以在您自己域的Web服务器上运行,并且可以透明地将请求转发到http://domainB.com ,则看起来它们实际上来自http://domainA.com ),则可以使用Ext.data.proxy.JsonP和称为JSON-P(带有填充的JSON)的技术,只要服务器位于http:/上,它就可以帮助您解决此问题。 /domainB.com设置为支持JSON-P响应。 See JsonPProxy's introduction docs for more details." 有关更多详细信息,请参见JsonPProxy的介绍文档。”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM