1

My webservice is hosted on one domain and my SharePoint site on another domain. I wanted to access my web service methods from client script (in SharePoint). What I am doing is

  1. Added reference of Web Service to my SharePoint project.
  2. Added an Application page.
  3. Created a Web Method in application page.
  4. This web method further access my web service method.
  5. From my client script I access my application page's web method.

Is this the right way to access a web service from client script?

Or can we directly access web service without any server side code or adding reference of web service? and having no cross domain issues

1

You may use cross-domain Ajax with JSON-P/JSONP, it was created specifically for this reason. Here are some references to get you started. If you need more specific examples, please let me know:

http://en.wikipedia.org/wiki/JSONP http://json-p.org/ https://stackoverflow.com/questions/2067472/what-is-jsonp-all-about

I also have this image - I'm not the creator - but I find it very useful.

Cross Domain Requests

0

try something like this using jQuery:

var webServiceGetInfoUrl = "http://MyWebService/Web.asmx/GetInfo";
var params = "{'param':'paramvalue'}";

$.ajax({
    type: "POST",
    url: webServiceGetInfoUrl,
    data: params,
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function(msg) {    
        // do something here
    },
    error: function(e){
        // do something here
    }
});

more details about jQuery ajax request here

  • I guess with this approach I'll have cross domain issues if web service is deployed to a different doamin. Isn't it? – V.B Jun 26 '14 at 5:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.