Invoking a Web Service using an HTTP Request

This section describes how to invoke a Web service using an HTTP request. It also describes how to configure a proxy server.

Do not use the Web Reference object as this feature is deprecated and will be removed in future versions.

Global Weather Web Service Overview

This topic describes a sample project implementation that utilizes a public Global Weather Web service, and demonstrates how to call the GetWeather function to return the weather for a specified city in a country. The same methodology can be applied to other Web service functions.

The source files for this project can be found at: https://www.extranice.com/EIS/AdditionalResources/RTSAR/Forms/AllItems.aspx

The Global Weather Web service and the GetWeather function are described in:

http://www.webservicex.net/ws/WSDetails.aspx?CATID=12&WSID=56

The GetWeather function uses two parameters, the CityName and CountryName.

The following is the SOAP request envelope used by the GetWeather Web service function:

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>

<GetWeather xmlns="http://www.webserviceX.NET">

<CityName>string</CityName>

<CountryName>string</CountryName>

</GetWeather>

</soap:Body>

</soap:Envelope>

The following is the SOAP response envelope returned by this function:

HTTP/1.1 200 OK

Content-Type: text/xml; charset=utf-8

Content-Length: length

<?xml version="1.0" encoding="utf-8"?>

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">

<soap:Body>

<GetWeatherResponse xmlns="http://www.webserviceX.NET">

<GetWeatherResult>string</GetWeatherResult>

</GetWeatherResponse>

</soap:Body>

</soap:Envelope>

Creating the Basic HTTP Request Business Entities

You need to create the basic business entities, including an HTTP Request base type and the two parameters (country and city) required by the GetWeather function of the Global Weather Web service.

To create the HTTP request business entities:

1. Create a new type called Demo WebService with Base type set to Http Request (from Library Types > Communication)..

2. Create an instance of Demo WebService and rename it Demo.

3. In the Instances tab, add Boolean as a New Boolean.
4. Add CountryName as a New Text, and set the Initial Value to Israel.
5. Add CityName as a New Text, and set the Initial Value to Eilat.
6. Expand Demo and select Content Type. Then set the Initial value to text/xml; charset=utf-8.

7. Select Request Method and set the Initial value to POST.

8. Select Url and set the Initial value to http://www.webservicex.net/globalweather.asmx?WSDL.

Creating the HTTP Request Function

To invoke the Web service create an InvokeWebMethod function. This function builds the SOAP request by concatenating various text strings in the form:

Header (including the Web service function opening tag) + <Parameter1> + Parameter1 + </Parameter1> + <Parameter2> + Parameter2 + </Parameter2> + Footer (starting with the Web service function closing tag)

Although this example only uses two parameters, this can be generalized for more parameters in a similar form.

The InvokeWebMethod function includes the following instructions:

1. Assigns an empty string to the XML Response property.
2. Prepares the SOAP request by concatenating the following items and assigns them to the XML Request:

The start of the request: <?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetWeather xmlns="http://www.webserviceX.NET">

The city name opening tag: <CityName>

The APA city name parameter: CityName

The city name closing tag: </CityName>

The country name opening tag: <CountryName>

The APA country name parameter: CountryName

The country name closing tag: </CountryName>

The name of the Web service function: </GetWeather>

The soap body closing tag: </soap:Body>

The end of the request: </soap:Envelope>

3. Posts the XML Request to the Web server for the Global Weather Web service. The Post Request method is called (you can also call the Post Request Asynchronous version). When completed, this populates the XML Response property.

To create the HTTP request function:

1. In the Types tab, under Weather service, add a InvokeWebMethod function.
2. Insert the following function instructions (the red text is pasted into a single <Add Text…> in the Concatenate method):

Assign into Xml Response

Assign Concatenate [ <CityName> CityName </CityName> <CountryName> CountryName </CountryName> </GetWeather> /soap:Body> </soap:Envelope>] into Xml Request

Post request to a web server of Weather service

Now that you have the data, you can use Text functions (such as Find Subtext Position or Extract Subtext) or XML library types to get the values (for example, find the position of <attribute> and </attribute> and then extract the value based on these positions).

Creating the HTTP Request Event Handler

You need to create an event handler that runs the InvokeWebMethod when the Boolean value is modified.

To create the HTTP request event handler:

1. In the Business Logic > Event Handler tab, create a New Event Handler.
2. From the When the following event is raised drop-down list, select The value of Boolean is modified.
3. Insert an instruction InvokeWebMethod of Demo.

Testing the HTTP Request Project

You need to compile the project and run Monitor to test the project.

To test the HTTP request project:

1. Ensure that the Real-Time Client process (RTClient.exe) is not running.
2. Click Generate to compile the project.

3. Ensure that the project compiles without errors.

4. Click Run Real-Time Client. The application runs.
5. Click Monitor.

6. Change the Boolean value. The Xml Response appears in the Demo business entity (this is the same response if you invoke it from the browser).

7. Click to expand the Xml Response.

Configuring a Web Service Proxy

You can manually configure a Web service proxy (WSP) on the Real-Time Server.

To manually configure a Web service proxy::

1. Back up <InstallationFolder>/Apache/conf/extra/wsp.rts.conf to <InstallationFolder>/Apache/conf/extra/wsp.rts.bak.

This file is also generated by the Real-Time Server during the successful import of a WSDL. If you import WSDL files, you must modify this file again after the import.

2. Open the <InstallationFolder>/Apache/conf/extra/wsp.rts.conf file for editing.
3. Override the content of the file with a new proxy request, for example:

Listen 18183

NameVirtualHost *:18183

<VirtualHost *:18183>

ProxyRequests off

ProxyPass /WSP/WeatherService http://www.webservicex.net/globalweather.asmx

ProxyPass /WSP/GeoIPService http://www.webservicex.net/geoipservice.asmx

ProxyPass /WSP/Internal_URI1 External_URL1

ProxyPass /WSP/Internal_URI2 External_URL2

</VirtualHost>

Each ProxyPass line represents a Web service. The /WSP/Internal_URI1 is the new URL that the client uses and the External_URL1 is the actual URL of the Web servicet.

4. If the RT Server uses a proxy server, add an additional line after the ProxyRequests off line (where 172.28.253.50:8080 is the proxy IP address):

ProxyRemote * http://172.28.253.50:8080

5. Save the file.
6. Restart the RTServer Apache service.

Using the Get Response Header Value

In version 7.1, the Get Response Header Value function was added.

Function / Event

Return Value / Parameter

Description

Syntax

Get Response Header Value

Text

Returns the value of the specified header key of a response. HTTP headers allow the client and the server to pass additional information with the request or the response. Few common http response headers are, Accept, Connection, and Date.

For details. refer to: https://en.wikipedia.org/wiki/List_of_HTTP_header_fields

Get Value of the of Http Request <Header> of the response