For this example Project I will be using a public web service hosted on http://www.webservicex.net that expects a zip code as input and returns the weather forecast for that area. Below is the SOAP envelope that the web service is expecting.
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<GetWeatherByZipCode xmlns="http://www.webservicex.net">
<ZipCode>68003</ZipCode>
</GetWeatherByZipCode>
</soap12:Body>
</soap12:Envelope>
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetWeatherByZipCodeResponse xmlns="http://www.webservicex.net">
<GetWeatherByZipCodeResult>
<Latitude>41.05411</Latitude>
<Longitude>96.39041</Longitude>
<AllocationFactor>0.002088</AllocationFactor>
<FipsCode>31</FipsCode>
<PlaceName>ASHLAND</PlaceName>
<StateCode>NE</StateCode>
<Details>
<WeatherData>
<Day>Thursday, May 21, 2009</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/sct.jpg</WeatherImage>
<MaxTemperatureF>79</MaxTemperatureF>
<MinTemperatureF>55</MinTemperatureF>
<MaxTemperatureC>26</MaxTemperatureC>
<MinTemperatureC>13</MinTemperatureC>
</WeatherData>
<WeatherData>
<Day>Friday, May 22, 2009</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/tsra30.jpg</WeatherImage>
<MaxTemperatureF>77</MaxTemperatureF>
<MinTemperatureF>58</MinTemperatureF>
<MaxTemperatureC>25</MaxTemperatureC>
<MinTemperatureC>14</MinTemperatureC>
</WeatherData>
<WeatherData>
<Day>Saturday, May 23, 2009</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/tsra30.jpg</WeatherImage>
<MaxTemperatureF>79</MaxTemperatureF>
<MinTemperatureF>59</MinTemperatureF>
<MaxTemperatureC>26</MaxTemperatureC>
<MinTemperatureC>15</MinTemperatureC>
</WeatherData>
<WeatherData>
<Day>Sunday, May 24, 2009</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/tsra30.jpg</WeatherImage>
<MaxTemperatureF>79</MaxTemperatureF>
<MinTemperatureF>59</MinTemperatureF>
<MaxTemperatureC>26</MaxTemperatureC>
<MinTemperatureC>15</MinTemperatureC>
</WeatherData>
<WeatherData>
<Day>Monday, May 25, 2009</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/tsra20.jpg</WeatherImage>
<MaxTemperatureF>78</MaxTemperatureF>
<MinTemperatureF>58</MinTemperatureF>
<MaxTemperatureC>26</MaxTemperatureC>
<MinTemperatureC>14</MinTemperatureC>
</WeatherData>
<WeatherData>
<Day>Tuesday, May 26, 2009</Day>
<WeatherImage>http://forecast.weather.gov/images/wtf/tsra30.jpg</WeatherImage>
<MaxTemperatureF>75</MaxTemperatureF>
<MinTemperatureF>56</MinTemperatureF>
<MaxTemperatureC>24</MaxTemperatureC>
<MinTemperatureC>13</MinTemperatureC>
</WeatherData>
<WeatherData />
</Details>
</GetWeatherByZipCodeResult>
</GetWeatherByZipCodeResponse>
</soap:Body>
</soap:Envelope>
The next task is to create an XML file that mimics the request format shown above and pass in the zip code to the appropriate element. The project will then use the HTTP Task to post this data to the web service. The response of the post (response XML format shown above) will be written to C:\temp\SOAPResponse.xml. Although not described in this topic I could then use the XML Read Task to grab the data, load it into a database, convert the data to another file format, email the information and more.
Here is the Project XML:
Code: Select all
<project name="SOAP call" mainModule="Main" version="1.0">
<module name="Main">
<createWorkspace />
<sql resourceId="Production 400">
<query outputVariable="data">
<statement>select zipcode from gademo.websrvdemo where company = 'Linoma Software'</statement>
</query>
</sql>
<xmlWrite outputFile="SOAPRequest.xml">
<header><?xml version="1.0" encoding="UTF-8" ?></header>
<element name="soap12:Envelope">
<element name="soap12:Body">
<forEach inputRowSetVariable="${data}">
<element name="GetWeatherByZipCode">
<attribute name="xmlns" value="http://www.webservicex.net" />
<element name="ZipCode" value="${data[1]}" />
</element>
</forEach>
</element>
<attribute name="xmlns:xsi" value="http://www.w3.org/2001/XMLSchema-instance" />
<attribute name="xmlns:xsd" value="http://www.w3.org/2001/XMLSchema" />
<attribute name="xmlns:soap12" value="http://www.w3.org/2003/05/soap-envelope" />
</element>
</xmlWrite>
<http host="www.webservicex.com">
<postRawData uri="/WeatherForecast.asmx " inputFile="SOAPRequest.xml" contentType="application/soap+xml; charset=utf-8" responseBodyDestination="file" responseBodyFile="C:\temp\SOAPResponse.xml" whenResponseBodyFileExists="overwrite" />
</http>
<deleteWorkspace />
</module>
</project>