Generate Client stub(Proxy) using Axis2c
Post date: May 27, 2011 3:21:11 AM
1. Creating solution
Start Visual Studio and create new solution, named "client".
Ensure, that Location field ends with "\Calculator".
While creating use template Win32=>Win32 Console Application, Click "OK". Click "Next".
In "Application Settings" dialog select "Console Application" and "Empty project", Click "Finish".
Solution is created.
Now click on "component" project and rename it to "calculator_client".
This manipulations is needed to create given directory structure.
2. Use service interface
Create directory Calculator\client\src and copy service interface file into this directory.
3. Generating client stub
To generate client stub start command prompt from Calculator\client\src directory and enter:
staff_codegen -tclientimpl Calculator.h
4. Implementing Calculator client
Open generated main.cpp and add next the comment "Invoke Your service here" lines as follows:
std::cout << "1 + 2 = " << pCalculator->Add(1, 2) << std::endl;
std::cout << "1 - 2 = " << pCalculator->Sub(1, 2) << std::endl;
5. Generating client Proxy
Proxy is a set of files, used to work with service
To generate client proxy start command prompt from Calculator\client\src directory and enter:
staff_codegen -tclient Calculator.h
These files will be generated:
CalculatorProxy.h
CalculatorProxy.cpp
Add all files into Solution:
Right click to "calculator_client" project, select "Add" => "Existing Item...". In opened dialog go inside "src" directory and select all files. Click "Add".
Notice: Don't include this files in the source code archive/CVS. This files must generated automaticaly while project build started.
6. Compilation
Go to Project Settings: Right click to "calculator_client" project and select "Properties". Click to Configuration Drop down box and select "All configurations" In the "Configuration properties" tree select "C/C++" item and enter these "Additional Include Directories":
$(STAFF_HOME)\include
Click "Apply".
In the "Configuration properties" tree open "Linker" subtree and click "Input". Fill in the "Additional Dependencies" field as follows:
staff_client.lib staff_common.lib rise.lib
Click "Apply".
In the "Linker" subtree click "General" item. Fill in the "Additional Library Directories" field as follows:
$(STAFF_HOME)\lib
Click "OK".
In the "Build Events" subtree click "Pre-Build Event" and fill in the "Command Line" field as follows:
staff_codegen -tclient -csrc -u Calculator.h
Set active solution configuration to release:
Click "Build" => "Configuration manager". Click "Active solution configuration" dropdown box and select "Release". Click "Close".
Compile the solution: "Build" => "Build Solution".
7. Start client
To start client open command prompt from Calculator\client\Release directory and enter:
calculator_client
You must see following results:
1 + 2 = 31 - 2 = -1
9. Client source directory structure
Calculator\client\Release -- compiled client
Calculator\client\src -- source directory
Calculator\client\src\Calculator.h -- service interface
Calculator\client\src\main.cpp -- client implementation
Calculator\client\src\CalculatorProxy.cpp -- client proxy (header)
Calculator\client\src\CalculatorProxy.h -- client proxy
Calculator\client\Calculator\client.sln -- visual studio solution file
Calculator\client\Calculator\client.vcproj -- visual studio project file
10. Download source code
Download source code of Calculator client.