In this introductory tutorial, Dimuthu Gamage explains how to use Axis2/Java tools to ease the development of Axis2/C Web Services.
Applies To
| Axis2/C [1] | 1.0.0 and higher [2] |
| Environment | Windows or Linux |
Introduction
Apache Axis2/C and Axis2/Java are two implementations of the same architecture of a Web service framework, implemented in different two languages. From the two, Axis2/Java contains many popular tools that provide great help for the development of Web services that is not limited to Axis2/Java developers but also for Axis2/C developers. In this tutorial, I will illustrate the use of two such Java tools, namely, WSDL2C and Java2WSDL tools to write Axis2/C Web services that includes both a client and a service.
When you begin to write a Web service you can choose from one of the two approaches available to developing a Web service. I.e. either the code-first approach or the contract-first approach. In code first approach, initially, you will code the interfaces you want to publish as the Web service. Then you generate the WSDL which then become the contract (at least the major part of the contract). On the other hand, with the contract-first approach, you first start with the WSDL and then generate code to provide and consume the service. From these two approaches you need to carefuly select the best, based on your problem environment. You can find some discussions on this topin in a few the articles published on Oxygen Tank[1] [3], as well.
WSDL2C is a tool that generates a 'C' code for a given WSDL. This is the tool you choose if you are following the contract-first approach. This will generate most of the code for you in terms of consuming or providing the service. Therefore, you will only need to worry about writing your business logic thereafter. WSDL2C tool acts as a 'C' extension to the WSDL2Code tool and both are shipped with the Axis2/Java project. WSDL2C also supports ADB Databinding[2] [4] that maps schema types in your WSDL to native C types and structures. This hides the complexity in handling XML and allows you to play around with just simple 'C' types.
Java2WSDL is a tool to generate the WSDL from Java code. It is the tool to be selected when you use the code-first approach. We still don't have a similar tool for C, like may be C2WSDL and I don't believe that there will be any in the near future. This kind of tool is hard to implement, mainly due to the lack of support for 'Reflection' in the 'C' language. Hence, code first approach is not an option for 'C' developers. So they have to start by writing the WSDL first. But because WSDLs are really complex, no one will try to write it by hand but instead, will use help from some kind of a tool. This is where Java2WSDL tool comes handy.
In this tutorial, I'm illustrating you a kind of hybrid approach but in fact, more or less the contract-first approach to develop an Axis2/C Web service. That is, first we write a simple Java interface to expose as the Web serivce and then we generate the WSDL from it using the Java2WSDL tool. Finally, we generate the 'C' code using WSDL2C tool. There are users[5] [5]in the Axis2/C list who have successfully used this approach in developing Axis2/C Web services.
In this tutorial, I will take you through the following steps:
Table of Contents
- Write a Java interface - Using simple types for the operation arguments [5]
- Generate the WSDL. [5]
- Generate the 'C' code of the service. [5]
- Writing your business logic for the service [5]
- Generate the 'C' code of the client. [5]
- Writing your 'C' Client. [5]
Axis2/Java nightly build[6] [6], rather than the releases, because this will surely have updated support for all the constructs in WSDL and XML Schema.
Next, make sure you have setup Axis2/Java correctly. Simply set the <path to axis2 java home>/bin directory to your PATH environment variable.
Then Go to the top of the directory hierarchy of your Java project, (in this case you should be in one directory level above the org directory in org/organizers/sports hierarchy).
Then type the following command[7] [7].
Java2WSDL.sh -cn org.organizers.sports.ScoreBoard
If you have setup things correctly, you should have ScoreBoard.wsdl file generated in your current directory. Just open it and check whether it seems like your expected WSDL.
Contract-First Web Services with Apache Axis2 [8] by Ajith Ranabahu
Author
Dimuthu Gamage is a Senior Software Engineer at WSO2. He is a commiter of the Apache Web Service project and a developer for WSF/PHP and WSF/Ruby projects.