Call WCF Web Service from Rasberry PI (Raspbian)

Install Gsoap on Rasberry PI running Raspbian

sudo apt-get install gSoap

Check installed gSoap version (May 1,2014 version is 2.8.7)

Download the correspondent toolchain (class generator) from sourgeforce (Installed library and toolchain must have SAME VERSION!)

Open console as Administrator and go to the tools folder. For Example:

cd C:\gsoap\gsoap-2.8.7\gsoap\bin\win32

Then use toolchain to build file as follow for c++:

wsdl2h -o test.h http://yourws.net/yourWCF/Service1.svc?wsdl
soapcpp2 -I"C:\gsoap\gsoap-2.8.7\gsoap\import" test.h

Import all generated files in your project (Exclude test.h , soapClientLib.cpp and soapServerLib.cpp)

Add stdsoap2.cpp and stdsoap2.h from toolchain directory.

Include *.nsmap and *Proxy.h in header.

Code Example

#include "Soap/BasicHttpBinding_USCOREIService1.nsmap"
#include "Soap/soapBasicHttpBinding_USCOREIService1Proxy.h"

int main(int argc, char *argv[])
{

BasicHttpBinding_USCOREIService1 s;
_ns1__GetData req;
_ns1__GetDataResponse resp;

int i = 29;
req.value = &i;

int err = s.__ns1__GetData(&req,&resp);

if (SOAP_OK == err)
cout << "WCF Response: " << *resp.GetDataResult << endl;
else
cout << "Error: " << err << endl;

}

Now you can see result in your console:

WCF Response: You entered: 29

If you receive Error 415 (Bad request) you have to change SOAP operation mode (WCF use an unusual charset for SOAP 1.1).

For removing soap 1.2 namespace from the your web-service client project you should to change strings

{"SOAP-ENV", "http://www.w3.org/2003/05/soap-envelope", "http://www.w3.org/2003/05/soap-envelope", NULL},
 {"SOAP-ENC", "http://www.w3.org/2003/05/soap-encoding", "http://www.w3.org/2003/05/soap-encoding", NULL},
 {"xsi", "http://www.w3.org/2001/XMLSchema-instance", "http://www.w3.org/*/XMLSchema-instance", NULL},
 {"xsd", "http://www.w3.org/2001/XMLSchema", "http://www.w3.org/*/XMLSchema", NULL},

to

{"SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/", NULL, NULL},
 {"SOAP-ENC", "http://schemas.xmlsoap.org/soap/encoding/", NULL, NULL},
 {"xsi", "http://www.w3.org/2001/XMLSchema-instance", NULL, NULL},
 {"xsd", "http://www.w3.org/2001/XMLSchema", NULL, NULL},

in all your .nsmap file and *Proxy.cpp file.


One Comments

  • Huijeong,Ha

    19 gennaio 2015

    Hello, I want to using WCF service at Raspberry Pi.

    What’s mean ‘Add stdsoap2.cpp and stdsoap2.h from toolchain directory.’?

    Reply

Lascia un commento