Overview

gSOAP is a portable development toolkit for C and C++ XML Web services and XML data bindings. It supports XML auto-serialization of C/C++ data. Includes WSDL/XSD schema binding tools, stub/skeleton compiler, Web server, SOAP/XML/MIME streaming, XML-RPC. Here is how to use it to build a web service client in Qt.

Preparation

gSOAP package contains pre-built tools in the gsoap/bin directory.

  • wsdl2h schema importer
  • soap2cpp stub/skeleton generator.

You require .wsdl and .xsd files of the web service to generate a c++ stub.

Modify your project

  • First use wsdl2h on a .wsdl file to generate a .h file, then use soap2cpp on the generated .h file to generate .h and .cpp files to be included in your Qt project.
  • Before using wsdl2h you have to modify the typemap.dat file, this file is present in gsoap/ws directory. Add a line in this file defining the namespace of your web service. Give any name to namespace and copy string from your .wsdl file following the tag.

  1. <definitions targetNamespace=http://something>

Add this line to typemap.dat file:

  1. Anything =”http://something”

  • Now run wsdl2h on .wsdl and .xsd files (from command prompt)

  1. wsdl2h –s  -t<path of typemap.dat> –o <name of generated .h file e.g chatpp.h> <path and name of .wsdl file>

(note .xsd file should be in same directory as .wsdl file)

  • Then use soapcpp2 on generated .h file (we assume that name of generated file is chatapp.h)

  1. soapcpp2  –i chatpp.h

this will generate multiple files

  1. soapstub.h
  2. soapH.h
  3. soapC.cpp
  4. soapchatappProxy.h
  5. soapchatappProxy.cpp
  6. chatapp.nsmap
  7. soapchatappsetvice.h
  8. soapchatappservice.cpp

and an xml file for each method in defined in .wsdl file.

  • now add

  1. soapstub.h
  2. soapH.h
  3. soapchatappProxy.h

as headers in to your qt project and then add

  1. soapC.cpp
  2. soapchatppProxy.cpp

as source

  • add include path of yor generated file in .pro file of your qt project or simply copy all of generated files to your project directory. Also add path of “libws2_32.a” in your .pro file I my case it is as under

  1. LIBS  += C:/NokiaQTSDK/mingw/lib/libws2_32.a

  • also add stdsoap2.h and stdsoap2.cpp from gsoap directory as header and source in your project.
  • now include chatapp.nsmap and chatappProxy.h in your main.cpp.
  • make an object of chatappProxy and use it to communicate with webservice.

above method worked for me while using gsoap with NokiaQtSDk on windows xp.

Categories: