AJAX: Web Service - How to cross-domain call the server

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • y2ktan
    New Member
    • Feb 2008
    • 6

    AJAX: Web Service - How to cross-domain call the server

    hi guys,
    I am building my web page using AJAX in ASP.Net, now I want to make a cross-domain call from my web application to my web service that both of them are hosted at different machine.

    I used the steps below to make the cross-domain call to the web service.

    First of all, I created a web service named as HRService.asmx and it is working fine by running under IIS 5.1.

    Secondy, I make a reference to the web service proxies by writing the code in the html body
    Code:
    <asp:ScriptManager ID="ScriptManager1" runat="server" >
                <Services>
                    <asp:ServiceReference Path="http://192.168.1.123/TestAjax/HRService.asmx"/>
                </Services>
            </asp:ScriptManager>
    After that I called the web service using javascript which is HRService.GetEm ployee(.....);

    However at the end, when I run the application it shows a message dialog that the class is 'undefined'.

    I did found the answer from msdn that we cannot reference to the web service directly by using ServiceReferenc e because hackers can use the JSON wire format to try and exploit cross domain scripts within browsers. Therefore it has been disabled due to security issues.

    So, now my question is, if we cannot make cross-domain call to the web service directly, then how can we remotely call the web service from Javascript?
    Does anyone know? Thank you very much.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Use a web proxy. Make a request to a script in your own domain which makes a Http request to the other domain and returns the response.

    Comment

    Working...