Creating a VB.NET Client for a ColdFusion Web Service
Interoperability is important to web services. The more platforms they can operate on, the more useful they are. This tutorial builds on an earlier one by showing that a web service created in ColdFusion (in a previous tutorial) can be consumed by a client written in Visual Basic.NET.
One of the cherished goals of web services is interoperability. Interoperability in its widest definition embraces different kinds of machine platforms (Intel Pentium, Apple, mainframes); operating with different operating systems, including Windows of all flavors, Mac, and Unix; and running applications (or web services) created by different kinds of programming software (Vb.Net, C#, Java, ColdFusion, Perl, Python, etc). The WS-I (Web Services Interoperability organization) whose members come from diverse organizations will oversee the development of web services specifications so that they will have the widest applicability.
In an earlier tutorial (which you can find here) it was shown that web services developed on a Microsoft .NET platform residing on a IIS server could be easily consumed by a client program written in ColdFusion. In this tutorial the web service created in ColdFusion is consumed by a client program written in Microsoft's VB.Net language. For the purposes of this tutorial we assume that the web service created by ColdFusion from an earlier tutorial is available on the IIS server.
The web service will be described first, followed by the description of how the client is created.
The complete description of the web service coded using ColdFusion was described in the earlier tutorial. Here is a brief description of the service containing some essential information.
The following ColdFusion function was converted into a web service in the previous tutorial.
<cffunction name="WelcomeMsg" returntype="string"> <cfargument name="name" type="string" required="yes"> <cfreturn "<h3><font color='blue'>Welcome to my Web Service Site</font></h3> " & arguments. name &"! " & "What would you like to do?"> </cffunction> <cfoutput> #WelcomeMsg("Jay")# </cfoutput>
This function requires a string and it processes the string by concatenating ! What would you like to do? to it. The function has a method, WelcomeMsg(), which eventually become the web service's method. In order to convert this function a ColdFusion component was constructed, which has the file name justFunction.cfc. This is the component that becomes discovered by the wsdl.
Step 1: Create a ASP.NET Application
From File -->New-->Project, open the various projects that can be created in MS VB.NET 2003 IDE. Choose to create an ASP.NET Web Application which is called ColdFusionNetClient. This adds a WebForm1. Delete this and add a new web form WebClient.aspx as shown in Fig.1.
The client, in this case CFDotNetWebClient, does not access the web service directly. It uses a middleman, a proxy to access the service. Now, how do you create a proxy? How does a proxy access the service? Let us see how to create a proxy first.
Microsoft Visual Studio .NET 2003 has a nice utility in its suite of utilities. This utility can be accessed by right clicking the References node in the solution explorer and choosing Add Web Reference. This brings up the wizard shown in Fig.3.
Fig.2
In Fig.3, by navigating to the ASMX file or the WSDL file, either by typing the URL directly into the drop-down or by clicking the drop-down by the side of URL: field, the Go button becomes active. In this case clicking on GO will search for the file, and if it exists it adds a proxy to the Web reference name: field, and provides a description in the area above it in the Web Services found at this URL: field. You may also browse the various places you may find this file in the indicated links on this utility's opening page, as seen in Fig.3.
Fig.3
Fig.4 shows the stage at which the Web reference has been located. Review all the items in this window. This figure shows that one service that is referenced by the WSDL is found on localhost (this is the local web server). The Service name is justFunction. Further this service has just one method, called WelcomeMsg(). Clicking on the button Add Reference will add this proxy to your project. If you want you may rename the localhost to some other name. It was renamed CFWsvcProxy as shown in Fig.5.
Fig.4
Fig.5 shows the Project in the solution explorer view with all the web references.
On the WebClient.aspx page, to the design view add a textbox which picks up the argument that is passed to the web service. You will also need a button to call the web service when clicked, and a Required Field Validator so that user is prompted to type in text, if he or she did not do so.
Fig.6
Fig.7 shows the code being written and the intellisense coming to the rescue. Observe the pop-up right after typing in "myCFsvc." inside "Response.Write()".
Fig.7
Fig.8 shows the completed code. Note that the reference to the proxy must be imported using the imports statement at the very top of the code a shown.
Fig.8
Browsing the Client
The rest is history. Right click the WebClient.aspx file in the Solution Explorer and choose to view it in your default browser. Then you will see the following display when you type text into the text box and click the button. The button click event called the web service via the proxy after passing what is typed into the text box. The service used the argument sent, and after processing sent the result to the client, which the client rendered to the display as seen in Fig.9
Fig.9
Summary
Interoperability is the goal and this tutorial touches upon a small fraction of this aspect. What has been shown in the last two tutorials are that web services created in ColdFusion (which are Java based) can be consumed by a Microsoft .NET Visual Studio created client, and that a Microsoft Visual Studio created Web Service (which is .NET based) can be consumed by a client application written in ColdFusion. Relatively speaking, the web services are interoperable between Java and .NET programming languages, as seen in these two tutorials in the Windows operating system.