0

i have created a wcf service in our server and it is hosted in IIS when i consume this web method in my html page which is in same solution or different solution in same server (ex: service url://www.xyz.com/projectname/service.svc/methodname
and domain url://www.xyz.com/projectname) when i call this url in ajax jquery with type='post' and datatype="J son" i am successfully getting response from my web method.but issue is when i create a sample html page in different server with different domain name (domain url: //www.abc.com/projectname and service url //www.xyz.com/projectname/service.svc/methodname ) i am unable to invoke the web service or i don't know exactly is it invoking the web method and it is displaying error message ,can any one please help me how to over come with any issue

user2914438
  • 1
  • 1
  • 2
  • 1
    Browsers enforce what is known as the [Same Origin Policy](http://en.wikipedia.org/wiki/Same-origin_policy) which prevents you from making cross domain AJAX calls. – Josh Nov 07 '13 at 13:51

1 Answers1

1

There are 2 possibilities for making cross domain AJAX calls:

  • JSONP (works only with GET requests if you use jquery and only with JSON response payloads) - your service should support JSONP response instead of simple JSON. Basically this means that it should wrap the standard JSON in a callback function that should be passed as parameter. You may take a look here for how to natively enable JSONP support in a WCF service here: How to natively enable JSONP for existing WCF service?
  • CORS (works with all HTTP verbs) - your web service must return the proper Access-Control-Allow-* response headers. And here's an example of how you could create a custom message inspector in WCF that would append those headers: http://enable-cors.org/server_wcf.html
Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928