GSOAP Tutorial

1

Click here to load reader

Transcript of GSOAP Tutorial

Page 1: GSOAP Tutorial

Option -i indicates that we want C++ proxy and server objects that include the client (and server) code, -C indicates client-side only files (soapcpp2 generates both client and server stubs and skeletons by default). Option -I is needed to import the stlvector.h file to support STL vectors.

gSOAP mit C++ Voraussetzungen:

• Ihr habt einen WebService eingerichtet, mit dem ihr es testen könnt. • Ihr habt mit dem PluginEditor ein C++ Projekt erstellt und wisst, dass dies bereits läuft.

Ladet von http://www.cs.fsu.edu/~engelen/soap.html die aktuelle gSOAP-Version runter (2.7.13 stable) Ihr benötigt aus dem Ordner \gsoap\bin\win32 die wsdl2h.exe und soapcpp2.exe außerdem den Ordner \gsoap\import und die beiden Dateien \gsoap\stdsoap2.cpp und \gsoap\stdsoap2.h Lasst den WebService laufen. Führt nun wsdl2h -o calc.h http://localhost:8080/TestWebApplication/CalculatorService?WSDL aus. Wobei die Adresse die Stelle der WSDL-Datei angibt. Dadurch wird die Header-Datei anhand der Methoden des WebServices erzeugt. Danach führt ihr soapcpp2 -i -C –I ../import calc.h aus.

Nun wurden einige Dateien erzeugt: (Namen natürlich je nach Service abweichend) Kopiert soapH.h, soapStub.h, calc.h, CalculatorServicePortBinding.nsmap, soapCalculatorServicePortBindingProxy.h und stdsoap2.h in euren include-Projektordner und soapC.cpp, soapCalucaltorServicePortBindingProxy.cpp und stdsoap2.cpp in euren src-Projektordner

Fügt die Dateien auch in Visual Studio ein, damit diese mitkompiliert werden. Ihr braucht dann folgende includes in eurem Code: #include "soapCalculatorServicePortBindingProxy.h" #include "CalculatorServicePortBinding.nsmap"

Der Code dazu könnte dann wie folgt ausschauen (Complex-Datatype): // Proxy besorgen CalculatorServicePortBindingProxy proxy; // Parameter anlegen ns1__add *addparam = new ns1__add(); addparam->sum1=4; addparam->sum2=8; // Response anlegen ns1__addResponse *result = new ns1__addResponse(); // Aufruf ausführen if (proxy.add(addparam,result)==SOAP_OK) updateModel(MDL_16, result->return_); else updateModel(MDL_16, "Fehler" );