doedje / jquery.soap

This script uses $.ajax to send a SOAP:Envelope. It can take XML DOM, XML string or JSON as input and the response can be returned as either XML DOM, XML string or JSON too.
352 stars 148 forks source link

Issue in accessing SAP Webservice from JQuery UI #93

Closed IshaAnjaly closed 8 years ago

IshaAnjaly commented 8 years ago

Hi, I have a SAP web service which I need to call from Jquery UI. Here is the webservice link->http://hawaii:3333/invoke/AMAT_iOMS.flows/getSingleOrderBOMFromSAP?SerialNumber=122&SONumber=1212

And here is the method function GetVarianData(){ $.soap({ url: 'http://hawaii:3333/invoke/AMAT_iOMS.flows/', method: 'getSingleOrderBOMFromSAP',

            data: {
                SerialNumber: '122',
                SONumber: '1212'
            },

            success: function (soapResponse) {
                var abc = "ABC";
                alert(abc);
                // do stuff with soapResponse
                // if you want to have the response as JSON use soapResponse.toJSON();
                // or soapResponse.toString() to get XML string
                // or soapResponse.toXML() to get XML DOM
            },
            error: function (SOAPResponse) {
                // show error
            }
        });
    }

But I am not able to get the data. If try the URL direcrtly in browser, I am getting the XML.

Can you please help here?

Thanks Anjaly

IshaAnjaly commented 8 years ago

Sorry it is not a web service. It is a HttpWebRequest. Please inform if the below code is correct.

$("#btnTestVarian").click(function (event) { debugger; $.get("http://hawaii:3333/invoke/AMAT_iOMS.flows/getSingleOrderBOMFromSAP?SerialNumber=122&SONumber=1212", function (data) { $("#response").html(data); alert("Load was performed."); }); });

doedje commented 8 years ago

Looking at the url you use... http://hawaii:3333/...... my first guess would be you are running into the limitations of Same origin policy

If you followed the instructions about contacting me you already checked that is not the case.... ;)

But still, please read the section on Same Origin Policy and come back at me if that is not casing your problem.....

Best regards

IshaAnjaly commented 8 years ago

Thank you Remy for the response. I am able to directly access the URL from browser. If I directly give it, I see the XML response on page. But not able to call from Jquery.

Client and the webmethod are in same intranet. Could not identify if its a same origin policy.

Can you please share some article to call HttpWebMethod from the mentioed URL from Jquery?

I am able to call it from C#. NET from code behind. Want to get the data from Jquery.

Thanks Anjaly

IshaAnjaly commented 8 years ago

I am getting this error

Server Error in '/' Application.

A potentially dangerous Request.Path value was detected from the client (:). Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: A potentially dangerous Request.Path value was detected from the client (:).

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[HttpException (0x80004005): A potentially dangerous Request.Path value was detected from the client (:).] System.Web.HttpRequest.ValidateInputIfRequiredByConfig() +9701768 System.Web.PipelineStepManager.ValidateHelper(HttpContext context) +53

IshaAnjaly commented 8 years ago

var request = 'http://hawaii:3333/invoke/AMAT_iOMS.flows/getSingleOrderBOMFromSAP?SerialNumber=122&SONumber=1212'; function CallPostService(requestUrl, postData, responseType, callback) { responseType = (responseType) ? responseType : '';

        $.ajax({
            type: 'POST',
            url: encodeURIComponent(requestUrl),// + '&responseType=' + responseType,
            dataType: "text",
            contentType: 'text/plain;charset=utf-8',
            data: null,
            success: function (r) {
                //callback(r);
                document.getElementById('outputDiv').innerHTML = "Success";
            },
            error: function (e) {
                document.getElementById('outputDiv').innerHTML = e.responseText;
            }
        });
    }
doedje commented 8 years ago

still think it is same origin policy..... same intranet is not good enough, same origin policy means both the page you're making the call from and the datasource should be on same protocol (http or https), same server (hawaii) and same port (3333) or else it won't work.... Please use google to learn more about same origin policy and how you can deal with it...