Consuming External Web Services

As mentioned earlier, browser security forbids the XMLHttpRequest object from connecting to any domain but the one on which the current web page resides. Therefore, if you need data from a remote web service (one that is on a different server), there is only one solution: create a server proxy on your server and then call this proxy from your JavaScript code.

The good news: Atlas comes with built-in support for proxying such web services calls, namely a technology referred to as a web service bridge. In the following sections, we will create pages that get data from two of the most popular commercial web services: the Google search web service and the Amazon e-commerce web service. The techniques shown here can easily be adapted to any other SOAP web service.

The secret behind this lies in a new file extension that the Atlas installer prompted you to register with IIS (see Chapter 1): .asbx. Files with this extension can contain XML markup that provides information about a local (server-based) proxy class for a web service. The web page’s JavaScript code just connects with the .asbx file, which then takes care of communication with the remote service. Figure 10-5 shows this mechanism.

The client page calls the server bridge, which then calls the remote web service

Figure 10-5. The client page calls the server bridge, which then calls the remote web service

Get Programming Atlas now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.