简体   繁体   中英

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:

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. Is there a way to modify our javascript client to connect to the new WS-ReliableMessaging-enabled service? 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?

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:

"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.

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. See JsonPProxy's introduction docs for more details."

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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