| |
Abstract One of the big promises of web services is universal interoperability because of the use of platform and language independent protocols such as SOAP. My skepticism about this led me to build an experiment in order to prove that this theory was true in practice.
This experiment consists of the following two parts:
- A Web service that converts temperatures from Fahrenheit degrees to Celsius degrees exposed using a web service engine for Java.
- A Web service consumer in ASP .NET using Visual Basic.
This tutorial assumes basic understanding of Web Services, more specifically about SOAP (Simple Object Access Protocol) and WSDL (Web Services Description Language). It also assumes familiarity with the use of Visual Studio .NET and some understanding of Java.
The Java Web Service provider The Web Services engine for java that I chose to use was , the Apache eXtensible Interactive System. AXIS is the successor of the implementation. Although the latest release is version alpha 3, it has features that can significantly accelerate Web Services development, and resemble some that are present in Microsoft .NET:
-
Easy creation. Simply take any .java source file, replace the extension with .jws and put it in the appropriate directory.
-
Automatic exposure. The WSDL file is automatically generated by accessing the url of the web service and adding "?WSDL", just like in ASP .NET with .asmx files. For example: http://localhost/MyService.jws?WSDL
-
Tool for generating service proxy. A program that takes as input a WSDL file and generates the proxy/stub classes for accessing the web service in Java. This tool is named Wsdl2java, and is the equivalent of wsdl.exe in the .NET framework.
I will not explain in detail how to setup AXIS (detailed instructions can be ), if you are familiar with other Apache software, the procedure will look familiar:
- In addition to the of your choice, you will need a Servlet/JSP Server implementation (e.g. Jakarta Tomcat). I used
- Additionally you need to get a JAXP 1.1 XML compliant parser, either or are fine, but the .jar files need to be included in the classpath, or copied into the lib directory.
- The "webapp" folder of axis needs to be copied into the webapps folder of tomcat and the axis .jar files need to be included in the classpath.
Next we need to create the actual web service code. This web service will include one method to convert Fahrenheit degrees to Celsius degrees. The file is to be named FToCService.jws and should be placed under the axis folder. The source code required for the Web Service looks like this:
public class FToCService {
public static float FToC (int fahrenheit) {
return (float)(fahrenheit-32)*5/9;
}
}
|
The ASP .NET Web Service consumer Now that the web service is created and exposed, we can use wsdl.exe from Microsoft .NET framework to generate a proxy class, which will be used by our ASP .NET application to consume the service. This is done from the Command Prompt:
C:\Inetpub\wwwroot\ws>wsdl /language:vb /namespace:JavaService http://localhost:8080/axis/FToCService.jws?WSDL
This generates the FToCService.vb which should be added to a ASP .NET Project in VB using Visual Studio .NET, and needs to be compiled. After doing this we can use it from a ASP .NET web form (named ServiceClient.aspx):
| |
<%@ Page Language="vb" Inherits="ws.ServiceClient" %>
|
<HTML>
<SCRIPT runat="server">
Sub submitBtn_Click(sender As Object, e As EventArgs)
Dim myService As New JavaService.FToCService()
celsius.Text = myService.FToC(fahrenheit.text) & " °C"
End Sub
</SCRIPT>
<BODY>
<FORM method="post" runat="server">
<asp:TEXTBOX id="fahrenheit" runat="server" width="30" />°F
<asp:Button id="submitBtn" runat="server" text="Convert" onclick="submitBtn_Click" />
<BR>
<asp:LABEL id="celsius" runat="server" />
</FORM>
</BODY>
</HTML>
|
That's all that needs to be done. Upon submitting the form on ServiceClient.aspx, the java web service will be consumed, demostrating the interoperability and language independency of web services.
|
|