Difference between revisions of "How to use gSOAP with Qt for Web Service Client"

From Qt Wiki
Jump to: navigation, search
 
Line 1: Line 1:
=Overview=
+
[[Category:Developing_with_Qt]]<br />[[Category:HowTo]]<br />[toc align_right=&quot;yes&amp;quot; depth=&quot;3&amp;quot;]
  
gSOAP is a portable development toolkit for C and C++ <span class="caps">XML</span> Web services and <span class="caps">XML</span> data bindings. It supports <span class="caps">XML</span> auto-serialization of C/C++ data. Includes <span class="caps">WSDL</span>/XSD schema binding tools, stub/skeleton compiler, Web server, <span class="caps">SOAP</span>/XML/MIME streaming, <span class="caps">XML</span>-<span class="caps">RPC</span>. Here is how to use it to build a web service client in Qt.
+
= Overview =
  
==Preparation==
+
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.
  
* Download and unzip the [http://sourceforge.net/projects/gsoap2/ gSOAP package] ''[sourceforge.net]''.
+
== Preparation ==
  
gSOAP package contains pre-built tools in the <code>gsoap/bin</code> directory.
+
* Download and unzip the &quot;gSOAP package&amp;quot;:http://sourceforge.net/projects/gsoap2/.
  
* <code>wsdl2h</code> schema importer
+
gSOAP package contains pre-built tools in the &lt;code&amp;gt;gsoap/bin&amp;lt;/code&amp;gt; directory.
* <code>soap2cpp</code> stub/skeleton generator.
 
  
You require <code>.wsdl</code> and <code>.xsd</code> files of the web service to generate a c++ stub.
+
* &lt;code&amp;gt;wsdl2h&amp;lt;/code&amp;gt; schema importer
 +
* &lt;code&amp;gt;soap2cpp&amp;lt;/code&amp;gt; stub/skeleton generator.
  
==Modify your project==
+
You require &lt;code&amp;gt;.wsdl&amp;lt;/code&amp;gt; and &lt;code&amp;gt;.xsd&amp;lt;/code&amp;gt; files of the web service to generate a c++ stub.
  
* 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.
+
== Modify your project ==
* 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.
 
  
Add this line to <code>typemap.dat</code> file:
+
* First use &lt;code&amp;gt;wsdl2h&amp;lt;/code&amp;gt; on a .wsdl file to generate a .h file, then use &lt;code&amp;gt;soap2cpp&amp;lt;/code&amp;gt; on the generated .h file to generate .h and .cpp files to be included in your Qt project.
 +
* Before using &lt;code&amp;gt;wsdl2h&amp;lt;/code&amp;gt; you have to modify the &lt;code&amp;gt;typemap.dat&amp;lt;/code&amp;gt; file, this file is present in &lt;code&amp;gt;gsoap/ws&amp;lt;/code&amp;gt; directory. Add a line in this file defining the namespace of your web service. Give any name to &lt;code&amp;gt;namespace&amp;lt;/code&amp;gt; and copy string from your .wsdl file following the tag.
  
* Now run <code>wsdl2h</code> on .wsdl and .xsd files (from command prompt)
+
<code>&lt;definitions targetNamespace=http://something&amp;gt;<code>
 +
 
 +
Add this line to &lt;code&amp;gt;typemap.dat&amp;lt;/code&amp;gt; file:
 +
 
 +
</code>Anything =”http://something”</code>
 +
 
 +
* Now run &lt;code&amp;gt;wsdl2h&amp;lt;/code&amp;gt; on .wsdl and .xsd files (from command prompt)
 +
 
 +
<code>wsdl2h –s -t&amp;lt;path of typemap.dat&amp;gt; –o &lt;name of generated .h file e.g chatpp.h&amp;gt; &lt;path and name of .wsdl file&amp;gt;<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 <code>soapcpp2</code> on generated .h file (we assume that name of generated file is chatapp.h)
+
* Then use &lt;code&amp;gt;soapcpp2&amp;lt;/code&amp;gt; on generated .h file &amp;#40;we assume that name of generated file is chatapp.h&amp;amp;#41;
 +
 
 +
</code>soapcpp2 –i chatpp.h</code>
  
 
this will generate multiple files
 
this will generate multiple files
 +
 +
<code>soapstub.h<br />soapH.h<br />soapC.cpp<br />soapchatappProxy.h<br />soapchatappProxy.cpp<br />chatapp.nsmap<br />soapchatappsetvice.h<br />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.
  
 
* now add
 
* now add
 +
 +
<code>soapstub.h<br />soapH.h<br />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<br />soapchatppProxy.cpp</code>
  
 
as source
 
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
 
* 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
 +
 +
<code>LIBS += C:/NokiaQTSDK/mingw/lib/libws2_32.a<code>
  
 
* also add stdsoap2.h and stdsoap2.cpp from gsoap directory as header and source in your project.
 
* also add stdsoap2.h and stdsoap2.cpp from gsoap directory as header and source in your project.
Line 46: Line 64:
  
 
''above method worked for me while using gsoap with NokiaQtSDk on windows xp.''
 
''above method worked for me while using gsoap with NokiaQtSDk on windows xp.''
 
===Categories:===
 
 
* [[:Category:Developing with Qt|Developing_with_Qt]]
 
* [[:Category:HowTo|HowTo]]
 

Revision as of 14:47, 23 February 2015



[toc align_right="yes&quot; depth="3&quot;]

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 <code&gt;gsoap/bin&lt;/code&gt; directory.

  • <code&gt;wsdl2h&lt;/code&gt; schema importer
  • <code&gt;soap2cpp&lt;/code&gt; stub/skeleton generator.

You require <code&gt;.wsdl&lt;/code&gt; and <code&gt;.xsd&lt;/code&gt; files of the web service to generate a c++ stub.

Modify your project

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

<definitions targetNamespace=http://something&gt;

Add this line to <code&gt;typemap.dat&lt;/code&gt; file:

Anything =”http://something”

  • Now run <code&gt;wsdl2h&lt;/code&gt; on .wsdl and .xsd files (from command prompt)

wsdl2h –s -t&lt;path of typemap.dat&gt; –o <name of generated .h file e.g chatpp.h&gt; <path and name of .wsdl file&gt;

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

  • Then use <code&gt;soapcpp2&lt;/code&gt; on generated .h file &#40;we assume that name of generated file is chatapp.h&amp;#41;

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.