(mis)adventures in software development...

20 July 2011

Generating gSOAP stubs in C

Category Programming

I think I might have enjoying my recent foray into the weird world of web services and SOAP had it not felt so much like trying to fit a square peg in a round hole. Reverse engineering a communication protocol that has its roots in RS-232 serial coms was bad enough. But then to work out how to send that data over a web service interface defined by a third part…while maintaining backwards compatibility…in C…let’s just say it was even less fun that it sounds.

gSOAP was used to handle the SOAP stuff, and turned out to be easiest and most reliable part of the whole project…relatively speaking. Because this isn’t a scenario the gSOAP documentation emphasizes (although the info is in there, sortof), here are some crib notes.

So you have some xsd and wsdl files from a third party that specify a web service interface. And for better or worse, you want/need to work with straight C code, as opposed to C++.

Assuming wsdl and xsd files have been downloaded to a local directory, create a “typemap.dat” file in this directory and add a namespace prefix. For example, add a line similar to:

thirdparty = "http://xml.thirdparty.com/WS"

Then use wsdl2h to create the header file:

wsdl2h -c WebService.wsdl

This creates WebService.h.

Then generate the code stubs using soapcpp2:

soapcpp2 -c -C -x -pfilenameprefix WebService.h

The -c options means generate C code, while using the -C option generates only client side code.