October 12th, 2008Compiling and Debugging Axis2/C Services And Clients Using Visual Studio
Posted by dimuthu in Tutorial/Guide, axis2/c, web services 
I have been working in Linux for a long time and recently moved to windows for a little change. (Hopefully for a little time . I find it is really easy to create a project for an Axis2/C client or service with Visual Studio. (I’m using Visual Studio 2005). Anyway I thought it is better to write down it somewhere so someone may find it useful.
Compiling Axis2/C Client
I’m using the math sample for this guide. You can find the source code inside “samples\client\math” directory of any axis2/c binary or source.
Create a new Visual Studio C++ Project, Select the project type to ‘Win32 Console Application’. Give a name to the project (say ‘math_client’) and in the wizard choose ‘Empty Project’. Then you will have an empty C/C++ project. 
Add the source files of the math samples to the project. You can do this by right clicking the project name in the Solution Explorer and clicking Add->Existing Item. After this step you will have axis2_math_stub.h in the Header Files section and the axis2_math_stub.c and math_client.c in the Source files section. 
Add Axis2/C include file directory. For this, go to ‘Tools->Options’ from the menu and select ‘Projects and Solutions->VC++ Directories’ from the Tree menu. Select the ‘Include files’ from ‘Show Directories for:’ drop down menu and add the ‘Axis2/C installed dir/includes’ directory. Note that if you follow this to add include directories you only need to do this only once for all the projects. If you want to do this only specifically to this project Go to ‘Project->Properties’ from the menu and Go to ‘Configuration Properties->C/C++->General and add the directories under ‘Additional Include Directories’) 
Add Axis2/C library directory. Here is how you do this. Go to the VC++ Directories form mentioned in the step 3 and select ‘Library files’ from the ‘Show Directories for:’ drop down menu. Then add the ‘Axis2/C installed dir/lib’ directory. If you add this here all the following project will use this directory to search for libraries. If you want this only to this project just skip this step and do what is specially mentioned in the step 5. 
Declare what libraries to link. For this, go to ‘Project->Properties’ from the menu and select “Configuration Properties->Linker->Input’ from the tree menu. In the ‘Additional Dependencies’ Text box add the following Axis2/C libraries. 
•	axiom.lib 
•	axutil.lib 
•	axis2_engine.lib 
•	axis2_parser.lib 
If you skipped the step 4, you have to type the complete path for the libraries. 
So that’s all you have to do. You can compile and run the client using F5 or Ctrl+F5. 
Debugging Axis2/C Client
Since by default new project is created with the debug configurations, you can debug the program straight away. To test set a breakpoint at the start of the main function (in the math_client.c) and Run with Debugging (F5) 
Compiling Axis2/C Service
We will use the corrosponding math service to create a Visual Studio project. It is same as how you created the math client project. But it has very little differences. (It requires only one additional step)
Create a project in Visual Studio. This time select “Win32 Project” as the project type. Give a name to the project (“math_service”) and continue to the wizard. In there select the “Application Type” to be “DLL” and tick the “Empty Project” so we will have an empty project to build a DLL. 
Add the math service sample files to the project. You can find the source for the sample inside “samples\client\math” directory of the Axis2/c distribution. 
Add the Axis2/C include directory. If you have done it earlier using “Tools->Options” dialog box you don’t need to do that again since that settings persist over every project. But if you did it using “Project->Properties” dialog box you have to redo the step3 described in compiling client section for this project too. 
Add the Axis2/C library directory. Same as the step 4 in compiling client section. 
Declare the libraries to link. Same as the step 5 in the comping client section. 
Declare the “AXIS2_DECLARE_EXPORT” preprocessor constant. For this go to the “Project->Properties” and click the “Configuration Properties->C/C++->Preprocessor” and add the “AXIS2_DECLARE_EXPORT” at the end separated with a semi column. 
That is all needed to compile the service. Now you can build the project using “Build->BuildSolution or just type F7. 
Debugging Axis2/C Service
After you compile the source, you cand find the resulted DLL inside the debug directory of your project directory. Just copy it to the <axis2 installed dir>\services\math directory replacing math.dll file. 
Then Run the simple Axis2 Http Server in the <axis2 installed dir>\bin. 
Start the project you just created for the math service and go to “Debug->Attach To Process”. There you can see the list of running processes. Just select the axis2_http_server process. 
Now as a test create a breakpoint at the start of axis2_math_add function in the math.c file. (You will get a warning that no symbol is loaded for the file, but you can ignore that for the moment) 
Now send a request using the math client that you compiled earlier. You will see the breakpoint is hit in the service project. So you can debug the service as you like.