Axis C++ windows user guide

Creating And Deploying your own Web Service

Creating the web service
How to use the WSDL2WS tool on the command line
Deploying your web service
Writing the client
Running your sample

Before you follow this guide, make sure that you have followed the Windows Installation guide

Creating the web service


Currently axis supports two methods to create and deploy a Web Service.
Method 1) A top down approach where you start with a WSDL.
Method 2) A bottom up apporach where you start with a pre-written web service.

Here we discuss the first apporach since the tool to support Method 2 (i.e wcg.exe) is still at its primitive stage in this Alpaha Release.
Here the document is written with the idea that the user uses Visual C++ (VC). But user could use this guide with a different IDE of his choice.

Method 1
This method assums that the user has written the wsdl of the service which he needs to deploy. In this methods user will start with this wsdl and the tool will generate the web service skeleton and other required files.
1) Get your wsdl (eg:Calculator.wsdl)
2) Run the WSDL2WS tool (refer the section below 'How to use the WSDL2WS tool on the command line') and generate the server side skeletons and wrappers. These files will be in two new folder which are gentrated from the tool called 'ServerOut' and 'ClientOut'.
3) Create a VC workspace.
4) Create a 'Win32 Static Library' project in this workspace.
5) Add the following files to this project, from the generated 'ServerOut' folder. Calculator.cpp Calculator.h
6) Set the include path to the include directory of the binary distribution (These include files are in AXIS_EXTRACT/include/).
7) Fill the empty methods of the generated skelitons. Here the idea is
8) Generate the lib (eg: MyCalculator.lib)
9) Now create a 'Win32 Dynamic-Link Library' project.
10) Add the following files to this project, from the generated 'ServerOut' folder. CalculatorService.cpp CalculatorWrapper.cpp CalculatorWrapper.h
11) Set the include path to the include directory of the binary distribution.
12) Add the above created lib (Calculator.lib) to the library modules of this project.
13) Build and create the DLL. (Calculator.dll)

How to use the WSDL2WS tool on the command line


For using WSDL2Ws java tool on the command line you require jdk1.4 or above.

To use WSDL2Ws java tool you should set the CLASSPATH Environment Variable to point to the following jar files in AXIS_EXTRACT\lib\axisjava.

axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
saaj.jar
wsdl4j.jar
xml-apis.jar

The CLASSPATH Environment Variabe should have the absolute paths of the jars (including the jar file name) given as a semicolon separated list.

Open a command window. Change directory to AXIS_EXTRACT\lib\axis. We will call this folder as WSDL2WS_FOLDER.

Now copy the wsdl file (eg.Calculator.wsdl) which you use to the folder WSDL2WS_FOLDER.

Now run the following command to generate the server side skeletons and wrappers.

Java -classpath %classpath%;.\wsdl2ws.jar org.apache.axis.wsdl.wsdl2ws.WSDL2Ws Calculator.wsdl -o./ServerOut -lc++ -sserver

If the tools is successful the tool will display the files the it has generated. The skeletons and wrappers will be generated in [WSDL2WS_FOLDER]\ServerOut.

Run the following command to generate the client stubs.

Java -classpath %classpath%;.\wsdl2ws.jar org.apache.axis.wsdl.wsdl2ws.WSDL2Ws Calculator.wsdl -o./ClientOut -lc++ -sclient

The generated client stubs will be in [WSDL2WS_FOLDER]\ClientOut

Deploying your web service


Currently the AdminClient tool is having some known bugs. So this section shows you how to deploy your Web Service manually, without using the AdminClient tool.
Say the apache installation folder is APACHE_FOLDER.
(For the defalt installation this is "C:\Program Files\Apache Group\Apache" for apache 1.3.X and "C:\Program Files\Apache Group\Apache2" for apache 2.X).
1) Copy the above Calculator.dll to the folder APACHE_FOLDER/Axis/webservices.
2) Go and add the following in the server.wsdd at the service level. Make sure you add these line at the correct place, i.e at service level. (APACHE_FOLDER/Axis/conf/server.wsdd)

<service name="Calculator" provider="C:RPC" description="Calculator Web Service">
<parameter name="className" value="APACHE_FOLDER\Axis\webservices\Calculator.dll"/>
<parameter name="allowedMethods" value="add subtract "/>
</service>

SUCCESS ! Now you have deployed your web service

Writing the client


With the WSDL2WS tool you have almost developed your client. What you have to do next is write a file which has a main method and create a object of the stub and invoke your methods on that.
1) Create a vc workspace.
2) Create a 'Win32 Console Application'.
3) Add files to this project from the above generated 'ClientOut' folder.
4) Set the include path to the include directory of the binary distribution.
5) Add the following libs to the library modules path of this project.

AXIS_EXTRACT/lib/axis/
client.lib
Common.lib
engine.lib
Soap.lib
WSDD.lib
XML.lib

AXIS_EXTRACT/lib/xerces-c
xerces-c_2.lib
wsock32.lib
6) Create a file with the main method which looks similar to the following and add this file to this project.

#include "Calculator.h"
int main()
{ 
        Calculator c; 
        int result = c.add(40, 20);
        printf("result = %d", result);
        return 0;
}

7) Now build and create the Client.exe

Running your sample

1) Restart Apache.
2) Run the Client.exe

SUCCESS ! If you get the result, you are done.