Saturday, July 24, 2010

How to use wsdl file to generate c/c++ files

This setup is based on Debian/Ubuntu system and doesn't involve any installation of Apache/Axis

(1)Install Java (run-time package is enough, but javac is a bonus, though I don't think I used javac in this setup). Note:install some new version, I used version 1.6.

(2)Download Axis C++ bin from Apache.org, decompress it. Note that there is a lib/axisjava folder and all the necessary Axis Java files used by Axis C++ are in there, so we don't have to download Axis Java anymore (however, if you try to use log4j you HAVE TO download Axis Java bin/src). And make sure in lib/axis there is already a wsdl2ws.jar in place, or you have to install ant and build the jar from source (which I didn't do)

(3)Edit CLASSPATH environment variable, here is my CLASSPATH variable

AXIS_C_HOME="type in your full directory path where Axis C++ bin is decompressed to"
AXIS_C_LIB=$AXIS_C_HOME/lib/axisjava

CLASSPATH=$AXIS_C_HOME/lib/axis/wsdl2ws.jar:
$AXIS_C_LIB/axis.jar:
$AXIS_C_LIB/wsdl4j.jar:
$AXIS_C_LIB/commons-discovery.jar:
$AXIS_C_LIB/commons-logging.jar:
$AXIS_C_LIB/jaxrpc.jar:
$AXIS_C_LIB/saaj.jar:
$CLASSPATH

export CLASSPATH

Note: if you want to use log4j, it should be located in $/lib/log4j-version.jar
you will need to include this path to CLASSPATH also.

Also note: if you want to set this varibale permanent, put the above stuff in .profile in your home directory, logout, and login again to take effect. To make sure: printenv $CLASSPATH


(4)Now we're ready to generate some c/c++ files using wsdl templete, here are some examples to generate client side wrapper:

c++:
java org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -sclient -lc++ "your wsdl file full path"

c:
java org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -sclient -lc "your wsdl file full path"

if the above don't work (which shouldn't been the case...), try:

c++:
java -classpath $CLASSPATH org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -sclient -lc++ "your wsdl file full path"

c:
java -classpath $CLASSPATH org.apache.axis.wsdl.wsdl2ws.WSDL2Ws -sclient -lc "your wsdl file full path"


1 comment:

  1. Hi!
    I know that this topic is kinda old now but I am struggling to get this think done in Ubuntu. Whatever I do I get the message "java unable to initialize org.apache.axis.wsdl.wsdl2ws.WSDL2Ws". I have changed the CLASSPATHPATH in /etc/environment to what is provided here in that blog. Before that I was getting an error saying that java is unable to find that org.axis... stuff. I suppose it has to do with some of my files now? Maybe I have them too old or too new? I am using axis 1.4 files
    Thanks in advance!

    ReplyDelete