Browse DevX
Sign up for e-mail newsletters from DevX


Serving Business Graphics from a Web Service  : Page 3

In this previous article, you built a VB.NET chart server that used XML and XPath to serve up business graphics. This article explains how, with the help of a couple extra tools, you can extend the chart server to consume and display results specifically from a Web service.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The SOAP Load Function
A new function has been added to the chart server since the previous article's publication. This function uses the parameters defined in the charts.xml file above to discover and call the Web service using SOAP.

It needs to be as generic as possible so you can pass in the specifics for its location, namespace, and required functions. As such, the SOAP load function takes the following parameters:


Specifies the WSDL file containing the description of the web service.


Specifies the namespace and method for the action that we will be performing.


Specifies the fully qualified SOAP Method that will be used within the SOAP envelope.


Specifies the namespace to use.

Table 1: Parameters that are passed to the SOAP Load function and their description.

First, the function creates a Http connection object and points it at the WSDL for the Web service, which was automatically generated by Visual Studio.NET when you built the Web service. When consuming any Web service, you need to view the WSDL. To view the WSDL when a Web service is generated using Microsoft Visual Studio.Net, run the Web service, and get the standard Microsoft service front-end. At the top of the screen, there is a hyperlink to the 'Service Description'. This takes you to the WSDL for your Web service.

Note: When configuring a chart to consume a Web service, the <URL> setting must point to the WSDL file for the Web service. This allows the charter to automatically generate soap messages of the required structure.

In addition the function needs to specify the SOAP Action, which is the method that defines the function that you are going to call. In the WSDL file, find a node called:

<binding name="Service1Soap"> Within this node, there's a childnode called : <operation name="GetProductsData">

'GetProductsData' is the name of a public function defined within your Web service. Within this childnode, the SOAP action is specified. If you use the default settings when creating the Nwind Web service (above), the SOAP action for this function is defined as 'http://tempuri.org/GetProductsData'. The connector object uses this value in its 'SoapAction' property. You configure this value in the the <soapaction> node in the charts.xml file.

The following code shows how these properties are used to specify the SOAP connector to the desired Web service using VB.NET.

Dim connector As New MSSOAPLib30.HttpConnector30Class() connector.Property("EndPointURL") = strLocation connector.Property("SoapAction") = strSoapAction

Next you set up a SOAP Serializer object, which creates a SOAP command envelope. In this case, you're calling a simple function on the Web service which takes no parameters. The chart server is easily expanded to tokenize parameters within the charts.xml file and pass them into this function. The serializer object allows you to add these parameters as elements to pass to the Web service.

Figure 1: This is a sample of the data charted from the Northwind data source.

The most important part of the SOAP Load function is the 'StartElement' property setting. This setting passes the other configurable parameters. If you go back to the WSDL file again, and look at the binding node for the SOAP messages on this service, you will see that the node containing the soap action was called 'operation'.

The contents of this node should be set in the charts.xml file in the node. In addition, you need to specify the the wrapper namespace. Use the 'targetNameSpace' value specified in the WSDL with the name of the Web service and the message type appended. For example, you are using a SOAP message, so the wrapper name space would be 'http://tempuri.org/nwind/message'. This code shows how to create a serializer object that contains the SOAP message:

Dim serializer As New MSSOAPLib30.SoapSerializer30Class() serializer.Init(connector.InputStream) serializer.StartEnvelope("", "", "") serializer.StartBody("STANDARD") serializer.StartElement (strSoapFunction, strWRAPPERNAMESPACE, "", "") serializer.EndElement() serializer.EndBody() serializer.EndEnvelope() serializer.Finished()

Next, the function reads the response from the service using a SOAP reader class, and loads the contents of the response into an XML Document:

Dim reader As New MSSOAPLib30.SoapReader30Class() reader.Load(connector.OutputStream, "") Dim strTest As String strTest = reader.BodyEntries(0).xml Dim xDoc As New System.Xml.XmlDocument() xDoc.LoadXml(strTest) Return xDoc

Expanded Functionalities
Figure 1 shows the result of charting the Products table from the Northwind database, with the data exposed as a Web service, and an XPath variable specifying the UnitsInStock for all items whose unit price is greater than $40.

This shows the power and extensibility of the charting server. Given a URL or a WSDL file, the charter will consume the data and produce a chart according to your requirements.

Laurence Moroney is a freelance enterprise architect who specializes in designing and implementing service-oriented applications and environments using .NET, J2EE, or (preferably) both. He has authored books on .NET and Web services security, and more than 30 professional articles. A former Wall Street architect, and security analyst, he also dabbles in journalism, reporting for professional sports. You can find his blog at http://www.philotic.com/blog.
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date