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
Deploying your web service Using AdminClient Tool
Coding 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 in a primitive and frozen state.
Here the document is written with the idea that the user uses Visual C++ (VC). But the 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 method user will start with this wsdl and the tool will generate the web service skeleton and other required files.
1) There is a folder called "simple" inside the samples/server folder in your axiscpp binary distribution. Inside this you can find the relevant wsdl for the calculator sample .Get the 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.
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) as the input libraries 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. Create a folder of your choice and we will call this folder as WSDL2WS_FOLDER.

Now copy the wsdl file (eg.Calculator.wsdl) which you use to the folder WSDL2WS_FOLDER.
Copy the file wsdl2ws.jar from AXIS_EXTRACT\bin to WSDL2WS_FOLDER
Now change the directory to WSDL2WS_FOLDER and 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 file generation 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


Axis cpp user can use the AdminClient tool to deploy a service or manually deploy. The first 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 default 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>

Now you have deployed your web service

Deploying your web service Using AdminClient Tool


The wsdl2ws Tool generates the deploy.wsdd and the undeploy.wsdd files needed for the AdminClient. Once we have these files, we have to deploy the web service (in this case the calculator service) with the AdminClietn. We do this with the AdminClient.exe which comes with axiscpp binary distribution. A typical invocation of the AdminClient looks like this:

AdminClient <server> <Port> <wsddfile>


Adminclient localhost 80 deploy.wsdd

where local host would be the server where the Axis cpp server is hosted and 80 would be the port at which it runs.

Coding 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/
Axisclient.lib
AxisServer.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 Calculator.exe


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