Access the AccessBooks Web Service via an AJAX Request

Walks you through the process of sending an AJAX request to your deployed service using a browser that supports CORS.
Restriction: This topic applies only when the Enterprise Server feature is enabled.

Send an AJAX request

The service you have deployed can be accessed by client programs as well as browsers that support cross-origin resource sharing. In this segment of the tutorial, you attempt to access the service using such a browser for the purpose of observing the results.

We provide a test script, bookAJAXtest.html, that contains an AJAX request. You run this script in a browser that supports CORS.

  1. In Windows File Explorer, browse to the %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Interface Mapping Toolkit\ServiceInterfaces\BookDemo directory.
  2. Open the bookAJAXtest.html file in a browser that supports cross-origin resource sharing.
  3. After the browser refreshes, click the Read radio button.
  4. Type 1111 into the lnk_b_stockno field; then click Submit.

    Nothing happens!

    In fact, this is the expected result. The reason nothing happened is that your service interface's Allowed Origin field is empty, preventing the service from recognizing that your AJAX request is originating from an allowed source. The request and response are still being sent, but your browser is preventing you from seeing the response.

  5. Close the browser window.

In the next segment, you correct this problem.

Delete the previously deployed service

You need to reconfigure the AccessBooks Web service interface to enable it to accept an AJAX request from any origin, and then redeploy it to your enterprise server instance. To prepare the ESCORS enterprise server instance to accept the redeployed service interface, you need to delete the previously deployed service.

  1. In the Enterprise Server Administration window in Visual Studio, on the Home page, click the Edit button in the left-most column of the ESCORS table row.
  2. At the top of the page, click the Services tab.
  3. In the table row for your /temppath/AccessBooks/1.0 service, click the corresponding Delete button.
  4. Click OK.
  5. Click Home on the menu ribbon on the left side of the window. This returns you to the Home page.

Set deployment properties

  1. From the Visual Studio Solution Explorer, right-click the AccessBooks Web service; then click Properties.
  2. In the Allowed Origin field, type * (asterisk). This enables your enterprise server instance to accept all requests regardless of the origin.
  3. Save the project.

Deploy the AccessBooks Web Service

  • From the Solution Explorer, right-click the AccessBooks service interface; then click Deploy.

The Output window shows the progression of the deployment process.

View deployment results

Now that your service interface has once again been deployed as a Web service running on the ESCORS enterprise server instance, you can look at the details of the deployed service via Enterprise Server Administration.

  1. In the Enterprise Server Administration window, click the Details button for the ESCORS Services.

    In the row showing your service, AccessBooks, notice that the Current Status column shows all four operations as Available. This means that the service is ready to be accessed by a client. In addition, you should see that the Custom Configuration column for these operations now includes the following text:

    [response headers] Access-Control-Allow-Credentials=false Access-Control-Allow-Origin=*

    This indicates that your service is ready to be called by AJAX scripts.

  2. Close the Enterprise Server Administration window.

Resend the AJAX request

Now that you have reconfigured and redeployed the AccessBooks Web service, try running that HTML script again.

  1. In Windows File Explorer, browse to the %PUBLIC%\Documents\Micro Focus\Enterprise Developer\Samples\Interface Mapping Toolkit\ServiceInterfaces\BookDemo directory.
  2. Open the bookAJAXtest.html file in a browser that supports cross-origin resource sharing.
  3. Click the Read radio button
  4. Type 1111 into the lnk_b_stockno field; then click Submit.

    The following text should appear below the Submit button:

    Result: { "lnk_file_status" : "00", "lnk_b_text_details" 
    : { "lnk_b_title" : "LORD OF THE RINGS", "lnk_b_type" 
    : "FANTASY", "lnk_b_author" : "TOLKIEN" }, 
    "lnk_b_stockno" : "1111", "lnk_b_retail" : 15, 
    "lnk_b_onhand" : 4000, "lnk_b_sold" : 3444 }
  5. Click the Next radio button, and then click Submit.

    The following text should appear below the Submit button:

    Result: { "lnk_file_status" : "00", "lnk_b_text_details" 
    : { "lnk_b_title" : "OLIVER TWIST", "lnk_b_type" 
    : "FICTION", "lnk_b_author" : "DICKENS" }, 
    "lnk_b_stockno" : "2222", "lnk_b_retail" : 10, 
    "lnk_b_onhand" : 3000, "lnk_b_sold" : 2333 }
  6. Close your browser.

This concludes the tutorial.