Wednesday, March 21, 2012

Web Service Calls From AJAX - No Cross Domain? NOT!

The AJAX 2.0 documentation states that Web Services can not be called "cross domain". This is a browser side restriction, so says Microsoft support. While one might disagree, I think of cross-domain as meaning between machines on different internet domains (i.e. machine1.bigcompany.com and machine2.bigcompany.com are on the same domain while machine3.yourcompany.com is on a different domain). This is not what Microsoft means. The use of the term "cross domain" in the documentation means that machine1.bigcompany.com and machine2.bigcompany.com are on different domains and AJAX web service calls between them can not be made successfully . At least this is what MS support tells me. I have found however that I can create a page on machine1.bigcompany.com and call a web service on machine2.bigcompany.com. To do this requires that four conditions be true:

1) You use IE 7 as your browser;

2) do not select the "inline script" option on the scriptmanager/services attribute

3)call set_path in your javascript to set the endpoint of the web service to machine2;

4) both machine1.bigcompany.com and machine2.bigcompany.com are defined as within the INTRANET ZONE in IE 7.

Firefox has no option like "intranet zones" so I have been unable to get this to work with Firefox. I am still working on this.

By the way if you have the same AJAX web page deployed on two different machines (meeting the conditions discribed above) with AJAX "PageMethods" defined, you can call set_path on the

PageMethod using Javascript and make calls between machines for PageMethods also.

Hope This Helps

dlr

You can implment this for Cross Domain issue:
http://weblogs.asp.net/rashid/archive/2007/09/28/implement-jsonp-in-your-asp-net-application.aspx

No comments:

Post a Comment