Axis C++ Windows Developers Guide (Alpha)

BUILDING AND DEPLOYING AXIS C++
Getting a cvs checkout
Getting Apache and Xerces-C
Installing Apache and extracting Xerces-C
Setting up the build environment and building Axis
Deploying Axis in Apache
DEPLOYING A WEB SERVICE IN AXIS C++
Generating Serverside Skeletons/ wrappers and client side stubs
Using eclipse to build and run WSDL2Ws
Building and running WSDL2Ws on the command line
Building and Deploying the web service
CONSUMING THE WEB SERVICE WITH AXIS C++ CLIENT
Coding and Running the client

Building and Deploying Axis C++

Getting a cvs checkout

Visit http://ws.apache.org/ click on “axis” and then on “CVS Repository” to find details on accessing the CVS Repository. It will have instructions similar to the following.

“Anyone can checkout source code from our anonymous CVS server. To do so, simply use the following commands (if you are using a GUI CVS client, configure it appropriately):

cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
password: anoncvs

cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic checkout ws-axis

The examples given below will be based on these lines of instructions.

To use the command line cvs client go to http://www.cvshome.org, click on the "CVS Downloads" link. In the resulting page there will be link named "historical download pages", under the heading "CVS downloads", where you can download the cvs binaries for Windows. Download the Windows cvs binaries. Extract the cvs binaries from the downloaded zip file. There will be a “cvs.exe” file when this is extracted. Set the PATH environment variable to where “cvs.exe” is.
You would have to do the following to get a checkout from the command line cvs client.

cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic login
Now you will be prompted for the password. Enter the password.

password: anoncvs

Now enter the following cvs command to checkout the axis Repository.
cvs -d :pserver:anoncvs@cvs.apache.org:/home/cvspublic checkout ws-axis

The checkout of the repository will be created in the current directory in a folder named “ws-axis”

The checked out folder ws-axis will be referred to as [CHECKOUT_HOME] from this point on.
 

Getting Apache and Xerces-C

Xerces-C
Download the Xerces-C ( 32 bit binary release)from: http://xml.apache.org/xerces-c/download.cgi

Apache web server
Download the Apache web server from www.apache.org. Currently Axis supports apache 1.3.x and 2.X. This documentation was tested with Apache 1.3.28 and Apache 2.0.44. It is recommended that you download these versions.

Installing Apache and extracting Xerces-C

Install the Apache web server. By default Apache 1.3.X is installed in "C:\Program Files\Apache Group\Apache" and Apache 2.X in "C:\Program Files\Apache Group\Apache2". This location will be referred as [APACHE_HOME] from this point onwards.


This documentation was tested with the xerces version 2.3.0 which is distributed as xerces-c_2_3_0-win32.zip . Unzip the file xerces-c_2_3_0-win32.zip. The folder to which xerces is unzipped will be referred to as [XERCES_EXTRACT] from this point onwards.
 

Setting up the build environment

1)copy the contents inside the "[XERCES_EXTRACT] \include\xercesc “
to [CHECKOUT_HOME]\c\include\xercesc
2) Copy the include files.
For apache 1.3.X:
Copy the include files in "[APACHE_HOME]\include" directory to
"[CHECKOUT_HOME] \c\include\apache1_3\"
For apache 2.X:
Copy the include files in "[APACHE_HOME]\include" directory to "[CHECKOUT_HOME] \c\include\apache2_0\"

3) Copy the lib files from “[XERCES_EXTRACT] \lib” to “[CHECKOUT_HOME]\c\lib\win32\xercesc”
4) Copy the lib files.
For apache 1.3.X: copy the ApacheCore.lib file from “[APACHE_HOME] \libexec” to “[CHECKOUT_HOME]\c\lib\win32\apache1_3”.
For apache 2.X: copy libapr.lib, libhttpd.lib files from "[APACHE_HOME]\lib" to "[CHECKOUT_HOME]\c\lib\win32\apache2_0".
5) In Visual C++ (The version used for this documentation was Visual C++ 6.0) open the file Axis.dsw which is in [CHECKOUT_HOME]\ws-axis \c\ vc. In the workspace window “File View”, right click on either the project Apache1_3 or Apache2_0 and click on the “Set as Active Project” to make it the Active Project.
6) Again in Visual C++ right click on either the project Apache1_3 or Apache2_0 in the workspace window “File View” and then click on “Settings…” on the popup menu. Select the “link” tab. Select “General” from the Category drop down list. In the “Output file name” text box put the value “[APACHE_HOME]\modules\mod_axis.dll” and click “OK”.

7) In Visual C++ Go to “Build -> Rebuild All “ to build mod_axis.dll
 

Deploying Axis in Apache

1) Create a directory structure called “Axis” inside [APACHE_HOME] as follows

Axis
|__ libs ( Copy the two dll file from xerces-c-x.x-win32/bin and paste it inside)
|__ logs (log files are located here)
|__ conf (server.wsdd file is located here)
|__ webservices (The place to put webservice dlls)
|__ wsdls (The directory for the wsdl files of the deployed web services)

NOTE: If you copy xerces dll files to [APACHE_HOME]\Axis\libs from a version other than the one you used to build the Axis source with, you may have trouble starting up the Apache web server.

2) Set the “PATH” environment variable to the following directories.
[APACHE_HOME]
[APACHE_HOME]\Axis\libs

3) Change the apache configuration file [APACHE_HOME]\conf\httpd.conf to include the following lines at the bottom.

LoadModule axis_module modules/mod_axis.dll
<Location /axis>
SetHandler axis
</Location>


4)create a file in [APACHE_HOME]\Axis named “axiscpp.conf “ which should contain the following lines.

AXISLOGPATH:XXXX
WSDDFILEPATH:YYYY

Where XXXX will be the path to a file named AxisLog (The log file)and YYYY will be the path to the server.wsdd file.

i.e.
AXISLOGPATH: [APACHE_HOME]\Axis\logs\AxisLog //
WSDDFILEPATH: [APACHE_HOME]\Axis\conf\server.wsdd //

5)Set an environment variable named AXIS_HOME and give [APACHE_HOME]\Axis as the value.

6)Select start->programs->Apache HTTP server->Control Apache Server->stop to stop the apache server
(This is because apache will be started automatically by the installation program)

Open up a DOS terminal and give the command "apache -k start" to start apache
(IT IS IMPORTANT TO START APACHE THIS WAY.)

(NOTE:If a 126 error occurs check whether the “path” variable has been set correctly as mentioned
before and whether the correct versions of the xerces dlls have been copied as instructed before)

open a browser and verify whether you can browse http://localhost/ (or give the machines ip as http://xxx.xxx.xxx.xxx/). If apache is running you will see the Apache start page in the browser. 

Deploying a web service in Axis C++

Generating Serverside Skeletons/ wrappers and client side stubs

Using eclipse to build and run WSDL2Ws

In the checked out source code there is a tool “wsdl2ws” (i.e. wsdl-to-web services) written in java that generates server side Skeletons/wrappers and client side stubs using a given WSDL file. This Section describes how this is done.
To build and run the java tool this section uses the eclipse platform. For this documentation eclipse 2.1.0 was used and the jdk version used was j2sdk1.4.1_01. You will not be able to build the java tool with jdk versions below 1.4.0.

1)Start the eclipse platform IDE.
Go to File->New->Project.

Select java in the “New Project” dialog and click “Next”.

In the “New” dialog that appears give a project Name (e.g. test). In the “New dialog” keep the “use default” Tick Box checked.
Note down the path in the “Directory” Text Box. This location will be referred to as [SKELSTUB_HOME] from this point onwards. Click “Next”.

Another dialog named “New” will appear. Select the “Source” tab. Select the project that you created (i.e. test).
Click on “Add Folder…”. In the “Source Folder Selection” dialog that appears select the project that you created (i.e. test) and click “Create New Folder…”. In the “New Folder” dialog that appears give a folder name as “src” and click “OK”. Click “OK” in the “Source Folder Selection” dialog. Click “Yes” on the confirmation message box that pops up.

Click “Libraries” in the “New” dialog. Click “Add External JARs…”. In the “JAR Selection” dialog that appears browse to [CHECKOUT_HOME]\ contrib\wss4j\lib and select the following JARs.

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

Click “Open”.

Click “Finish” on the “New” dialog.

2) Copy the “org” folder inside [CHECKOUT_HOME]\ c\src\wsdl to [SKELSTUB_HOME]\src. The “org” folder contains the package structure for the WSDL2Ws java tool.
3) Go to eclipse and right click on the “Package Explorer” window and click on “Refresh” in the popup menu that appears. Now you should be able to see the source that was copied, in the “Package Explorer” window. By now eclipse would have built the WSDL2Ws tool.

For this demonstration we will use a Calculator web service and the WSDL file for that web service is Calculator.wsdl.

Copy the Calculator.wsdl to [SKELSTUB_HOME]

In eclipse go to “Run->Run…”.
In the “Run” dialog select the “Main” tab. In “Project” text box give the name of the project you created (i.e. test).
In the “Main Class” text box give the class as “org.apache.axis.wsdl.wsdl2ws.WSDL2Ws”.
 

Select the “Arguments” tab.

In the “Program Arguments” text box give the following argument.

“Calculator.wsdl -o./ServerOut -lc++ -sserver”.

NOTE: These are the arguments for the java tool WSDL2Ws. The usage of the WSDL2Ws is as follows.
Java org.apache.axis.wsdl.wsdl2ws.WSDL2Ws <wsdl file> -o<output directory>
-l<c|c++> -s<(server|client)>.
Also note that there cannot be any spaces after a switch (i.e. –o, -l).

Click “Run”.
Now the Skeletons/Wrappers will be generated and you will see messages in the eclipse console displaying the generated files. The generated Skeletons/Wrappers will be created in a folder named [SKELSTUB_HOME]\ServerOut as given in the arguments when the tool was run.

Similarly to generate the client stubs use the following arguments in eclipse and run.
“Calculator.wsdl -o./ClientOut -lc++ -sclient”.
The generated Stubs will be created in a folder named [SKELSTUB_HOME]\ClientOut.
 

Building and running WSDL2Ws on the command line

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

To build WSDL2Ws java tool you should set the CLASSPATH Environment Variable to point to the following jar files in [CHECKOUT_HOME]\ contrib\wss4j\lib.

axis.jar
commons-discovery.jar
commons-logging.jar
jaxrpc.jar
saaj.jar
wsdl4j.jar
xml-apis.jar
The CLASSPATH Environment Variable 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 [CHECKOUT_HOME]\c\src\wsdl.
We will refer to this directory as [SKELSTUB_HOME] as we did during generating Skeletons/Wrappers and Stubs with eclipse
Run the following command to build the java tool.
Javac -sourcepath . org\apache\axis\wsdl\wsdl2ws\WSDL2Ws.java

If the command finishes without any output then the java tool has been built.

Now copy the Calculator.wsdl file which we use in this example to [SKELSTUB_HOME]

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

Java -classpath %classpath%;. 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 stubs will be generated in [SKELSTUB_HOME]\ServerOut.

Run the following command to generate the client stubs.

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

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

Building and Deploying the web service

1) Start Visual C++.
2) Go to File->Open and open the workspace file “Axis.dsw” in [CHECKOUT_HOME]\ \c\vc.
3) Go to Project->Add To Project->New…
4) Select the “Projects” tab
5) Select “Win 32 Dynamic-Link Library”
6) Give a project name (e.g. ws1) and click “OK”.
7) In the dialog that appears select “An empty DLL project” click “Finish” and then “OK”.
8) When this procedure is followed the ws1 project files are created in [CHECKOUT_HOME]\c\vc\ws1.
9) Right click on the project that you created (i.e. ws1) and click “Add Files to Project…” on the menu that appears. In the “Insert Files into Project” dialog select the generated .cpp and .h files in [SKELSTUB_HOME]\ServerOut and click “OK”.
10) Right click on the project (i.e. ws1)again and click on “Settings…” on the menu that appears. Click the C/C++ tab and select “Preprocessor” from the “Category” Drop down list.
In the “Additional include directories” give “../../include”

11) Now business logic should be added to the generated Skeletons. The Skeletons in this case are Calculator.h and Calculator.cpp
12) Two methods are available for implementation in Calculator.cpp we shall implement them as follows.
int Calculator::add(int Value0, int Value1)
{
return Value0+Value1; //business logic
}
int Calculator::subtract(int Value0, int Value1)
{
return Value0-Value1; //business logic
}
13) Right click on the project (i.e. ws1) and click “Build” on the menu that appears. Visual C++ should be able to build the project without any errors now.

14) The ws1.dll will be build in [CHECKOUT_HOME]\c\vc\ws1\Debug by Visual C++
15) Place the built ws1.dll file in [APACHE_HOME] \ Axis \webservices
16) In addition to this you have to create sever.wsdd file in [APACHE_HOME]\Axis\conf

The server.wsdd file for this example is given below


<deployment>
<service name="Calculator">
<parameter name="className"
value="[APACHE_HOME]\Axis\webservices\ws1.dll"/>
<parameter name="allowedMethods" value="subtract add "/>
</service>
</deployment>

In this file [APACHE_HOME] should be replaced with the actual value of [APACHE_HOME] (i.e. For this case C:\Program Files\Apache Group\Apache )

Description of the server.wsdd file

The service element specifies the service name.
<service name="Calculator">

In this parameter element we specify the parameter className and it’s value, the location of the webservice dll.
<parameter name="className" value="C:\Program Files\Apache Group\Apache\Axis\webservices\ws1.dll"/>

In this parameter element we specify the parameter allowedMethods and its value, the methods exposed by the web service (i.e. subtract and add).
Note: A trailing space should be put after every allowed method.
<parameter name="allowedMethods" value="subtract add "/>

17) Now start the apache web server by typing “apache –k start”. If it is running type “apache –k restart”

18) Now type http://localhost/axis/ in a browser and you will see the “Welcome to Axis C++” page with a listing of deployed services (In this case the Calculator service only).
 

Consuming the web service with Axis c++ client

Coding and Running the client

1) Start Visual C++.
2) Go to File->Open and open the workspace file “Axis.dsw” in [CHECKOUT_HOME]\ \c\vc.
3) Go to Project->Add To Project->New…
4) Select the “Projects” tab
5) Select “Win 32 Console Application”
6) Give a project name (e.g. calclient) and click “OK”.

7) In the dialog that appears select “An empty project” click “Finish” and then “OK”.

8) When this procedure is followed the calclient project files are created in [CHECKOUT_HOME]\c\vc\calclient.
9) Right click on the project that you created (i.e. ws1) and click “Add Files to Project…” on the menu that appears. In the “Insert Files into Project” dialog select the generated .cpp and .h files in [SKELSTUB_HOME]\ClientOut and click “OK”.
10) Right click on the project (i.e. calclient) again and click on “Settings…” on the menu that appears. Click the “C/C++” tab and select “Preprocessor” from the “Category” Drop down list.
In the “Additional include directories” give “../../include”

11) Click the “Link” tab and select “Input” from the “Category” Drop down list.
Remove the contents of the “Object/library modules” and add the following libs to it.

Common_D.lib Soap_D.lib wsdd_D.lib Engine_D.lib xerces-c_2D.lib client_D.lib ws2_32.lib

In the “Additional library path” text box give the following, comma separated list of paths.

../../lib/win32/axis, ../../lib/win32/xercesc

Click “OK”.
 

Now the client should be coded. Basically this will be a main method. We will write the main method in the file Calculator.cpp. This is the stub generated by the java tool in the stub generation step.

Add the following main method to Calculator.cpp

void main()
{
Calculator cal;
int result = cal.add(22, 33);
printf("The result is : %d", result);
}

Right click on the project and click “Build” on the menu that appears.
If Visual C++ complains about missing libs go to Build->Rebuild All (Do make sure that the apache server is stopped). Now the client exe is built.
Start the apache by typing apache –k start and run the exe from Visual C++ by going to Build->Execute calclient.exe. Now you will see the SOAP Request, SOAP Response and the result printed by the main method that we coded.