Difference between revisions of "How to use gSOAP with Qt for Web Service Client"
Line 1: | Line 1: | ||
− | [[Category:Developing_with_Qt]] | + | [[Category:Developing_with_Qt]] |
+ | [[Category:HowTo]] | ||
+ | [toc align_right="yes" depth="3"] | ||
= Overview = | = Overview = | ||
Line 7: | Line 9: | ||
== Preparation == | == Preparation == | ||
− | * Download and unzip the | + | * Download and unzip the "gSOAP package":http://sourceforge.net/projects/gsoap2/. |
− | gSOAP package contains pre-built tools in the | + | gSOAP package contains pre-built tools in the <code>gsoap/bin</code> directory. |
− | * | + | * <code>wsdl2h</code> schema importer |
− | * | + | * <code>soap2cpp</code> stub/skeleton generator. |
− | You require | + | You require <code>.wsdl</code> and <code>.xsd</code> files of the web service to generate a c++ stub. |
== Modify your project == | == Modify your project == | ||
− | * First use | + | * First use <code>wsdl2h</code> on a .wsdl file to generate a .h file, then use <code>soap2cpp</code> on the generated .h file to generate .h and .cpp files to be included in your Qt project. |
− | * Before using | + | * Before using <code>wsdl2h</code> you have to modify the <code>typemap.dat</code> file, this file is present in <code>gsoap/ws</code> directory. Add a line in this file defining the namespace of your web service. Give any name to <code>namespace</code> and copy string from your .wsdl file following the tag. |
− | <code> | + | <code><definitions targetNamespace=http://something><code> |
− | Add this line to | + | Add this line to <code>typemap.dat</code> file: |
</code>Anything =”http://something”</code> | </code>Anything =”http://something”</code> | ||
− | * Now run | + | * Now run <code>wsdl2h</code> on .wsdl and .xsd files (from command prompt) |
− | <code>wsdl2h –s -t | + | <code>wsdl2h –s -t<path of typemap.dat> –o <name of generated .h file e.g chatpp.h> <path and name of .wsdl file><code> |
(note .xsd file should be in same directory as .wsdl file) | (note .xsd file should be in same directory as .wsdl file) | ||
− | * Then use | + | * Then use <code>soapcpp2</code> on generated .h file (we assume that name of generated file is chatapp.h) |
</code>soapcpp2 –i chatpp.h</code> | </code>soapcpp2 –i chatpp.h</code> | ||
Line 39: | Line 41: | ||
this will generate multiple files | this will generate multiple files | ||
− | <code>soapstub.h | + | <code>soapstub.h |
+ | soapH.h | ||
+ | soapC.cpp | ||
+ | soapchatappProxy.h | ||
+ | soapchatappProxy.cpp | ||
+ | chatapp.nsmap | ||
+ | soapchatappsetvice.h | ||
+ | soapchatappservice.cpp</code> | ||
and an xml file for each method in defined in .wsdl file. | and an xml file for each method in defined in .wsdl file. | ||
Line 45: | Line 54: | ||
* now add | * now add | ||
− | <code>soapstub.h | + | <code>soapstub.h |
+ | soapH.h | ||
+ | soapchatappProxy.h</code> | ||
as headers in to your qt project and then add | as headers in to your qt project and then add | ||
− | <code>soapC.cpp | + | <code>soapC.cpp |
+ | soapchatppProxy.cpp</code> | ||
as source | as source |
Revision as of 09:10, 25 February 2015
[toc align_right="yes" depth="3"]
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
- Download and unzip the "gSOAP package":http://sourceforge.net/projects/gsoap2/.
gSOAP package contains pre-built tools in the gsoap/bin
directory.
wsdl2h
schema importersoap2cpp
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 usesoap2cpp
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 thetypemap.dat
file, this file is present ingsoap/ws
directory. Add a line in this file defining the namespace of your web service. Give any name tonamespace
and copy string from your .wsdl file following the tag.
<definitions targetNamespace=http://something>
Add this line to
typemap.dat
file:
Anything =”http://something”
- Now run
wsdl2h
on .wsdl and .xsd files (from command prompt)
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)
soapcpp2 –i chatpp.h
this will generate multiple files
soapstub.h
soapH.h
soapC.cpp
soapchatappProxy.h
soapchatappProxy.cpp
chatapp.nsmap
soapchatappsetvice.h
soapchatappservice.cpp
and an xml file for each method in defined in .wsdl file.
- now add
soapstub.h
soapH.h
soapchatappProxy.h
as headers in to your qt project and then add
soapC.cpp
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
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.