Accessing a remote REST service in an AJAX client
As we have discussed in the Consuming a WCF service from an ASP.NET AJAX client recipe, ASP.NET AJAX script can consume a WCF REST service (with webScript behavior enabled) through the ScriptManager
control. However, this kind of AJAX script client can only consume WCF services that are hosted in the same web application as the Web pages. Trying to access a remote WCF service through the ASP.NET AJAX script will not work. Don’t worry, we have found some alternative ways to work around this problem.
In this recipe, we will demonstrate a very simple way to call a remote WCF REST service in an ASP.NET web page via jQuery-based AJAX script.
How to do it...
Since XSS protection prevents AJAX scripts from sending HTTP POST requests to a remote service host, the solution we will demonstrate here is to use AJAX script to consume a remote WCF REST service through the HTTP GET method.
Configure the target WCF REST service to open HTTP GET-based endpoints...