The following example is going to look at building a report that uses a Web Service Data Source and dataset to retrieve a weather forecast based on a ZIP code. The reason behind my including this separate from the others is the fact that during the first edition of this book there were no real free web services to utilize as an example. However, these days there are plenty of free web services available to utilize for this purpose. Let's now build a report:
Create a new report called WeatherByZipCode.rptdesign.
Choose the blank template.
From the Data Explorer, select Data Source | New Data Source.
From the list of Data Source types, choose Web Services Data Source, and set Data Source Name as dsWeatherDataSource.
Call the new dataset as dsetWeatherByZip. Click Next.
From the list of available web services, click down to the WeatherForcastSoap and select GetWeatherByZipCode.
Click Next for ZipCode parameter as it is the only parameter for this web service.
The next screen will show a preview of the web service request. If one is familiar with SOAP request formats, he/she can verify that it is correct. Otherwise, click on Edit Parameter.
Click the Edit button and enter ZIP code as the default parameter. Click OK, then click Next at the parent window.
For the SOAP response edit dialog, leave all the values as default.
The next screen will define an XPATH expression, defining that the rows are in the resulting XML. In this case, we will define a XPATH that points to the result sequence for the weather data. Use the tree view to find the WeatherData node and click on the> arrow, which automatically sets the XPATH expression.
On the next screen, we need to define the column mapping for each row. Select the WeatherData node and click on the>> arrow. This will add all the child elements as columns for the resulting row.
Click on Show Sample Data to get a preview of the data and verify that the XPATH expressions are retrieving the correct data.
Click Close on the sample data dialog, and Finish in the Dataset wizard.
The Edit Data Set dialog will look very familiar at this point. One can go back and modify any of the values set in the wizard. Click OK in the Edit Data Set dialog.
Drag the Weather dataset over to the Report Editor.
At this point, the report is done. However, let's add something extra to it. The WeatherImage column points to a URL that will have an icon with the weather conditions. Let's put in a dynamic image item that will reflect this. Delete the WeatherImage text item from the second row, second column.
Insert a new Image item into the empty second column, second row.
In the Edit Image dialog, change the button to the right of the Enter URI textbox to Javascript Syntax.
As an expression, enter row["WeatherImage"]. We can use the list boxes at the bottom to input this.
Click OK and then click the Insert button.
Save the report and preview it.
Web service parameters will vary based on the hosting server. It is possible to use Java classes to serve as the web service proxy, if one uses something like Apache Axis. This is a simple example that will get one familiar with the possible uses of this Data Source.