Getting Started: a quick how-to tutorial on gSOAP. There is also another older how-to start with gSOAP. User Guide: the guide with everything gSOAP. But you may want to start with understanding XML Data Bindings Fact Sheet: a quick overview of key features. Tutorials with details on how to stay secure with gSOAP. Licensing: dual licensed as open source GPL v2 and commercial-use license (available for purchase).
wsdl2h -o outfile.h infile.wsdl |
wsdl2h -o XMethodsQuery.h http://www.xmethods.net/wsdl/query.wsdl |
|
wsdl2h -c -o quote.h http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdl |
//gsoap ns1 service name: net_DOTxmethods_DOTservices_DOTstockquote_DOTStockQuoteBinding
//gsoap ns1 service type: net_DOTxmethods_DOTservices_DOTstockquote_DOTStockQuotePortType //gsoap ns1 service port: http://66.28.98.121:9090/soap //gsoap ns1 service namespace: urn:xmethods-delayed-quotes //gsoap ns1 service documentation: Definitions generated by the gSOAP WSDL parser 1.0 // Service net.xmethods.services.stockquote.StockQuoteService : net.xmethods.services.stockquote.StockQuote web service //gsoap ns1 service method-style: getQuote rpc //gsoap ns1 service method-encoding: getQuote http://schemas.xmlsoap.org/soap/encoding/ //gsoap ns1 service method-action: getQuote urn:xmethods-delayed-quotes#getQuote int ns1__getQuote(char *symbol, float &Result); |
//gsoap ns1 service name: Quote |
soapcpp2 -c quote.h |
int soap_call_ns1__getQuote(struct soap *soap, char *URL, char *action, char *symbol, float &Result); |
#include "soapH.h" // obtain the generated stub
#include "Quote.nsmap" // obtain the generated XML namespace mapping table for the Quote service main() { struct soap *soap = soap_new(); float quote; if (soap_call_ns1__getQuote(soap, NULL, NULL, "IBM", quote) == SOAP_OK) printf("Current IBM Stock Quote = %g\n", quote); else // an error occurred soap_print_fault(soap, stderr); // display the SOAP fault on the stderr stream } |
#include "soapQuoteProxy.h" // get proxy #include "Quote.nsmap" // get namespace bindings int main() { Quote q; float r; if (q.ns1__getQuote("IBM", r) == SOAP_OK) std::cout << r << std::endl; else soap_print_fault(q.soap, stderr); return 0; } |
// Contents of file "calc.h":
//gsoap ns service name: calculator //gsoap ns service style: rpc //gsoap ns service encoding: encoded //gsoap ns service port: http://mydomain/path/calculator.cgi //gsoap ns service namespace: urn:calculator int ns__add(double a, double b, double &result); int ns__sub(double a, double b, double &result); int ns__sqrt(double a, double &result); |
soapcpp2 calc.h |
// Contents of file "calc.cpp":
#include "soapH.h" #include "calculator.nsmap" #include <math.h> main() { soap_serve(soap_new()); // call the incoming remote method request dispatcher } // Implementation of the "add" remote method: int ns__add(struct soap *soap, double a, double b, double &result) { result = a + b; return SOAP_OK; } // Implementation of the "sub" remote method: int ns__sub(struct soap *soap, double a, double b, double &result) { result = a - b; return SOAP_OK; } // Implementation of the "sqrt" remote method: int ns__sqrt(struct soap *soap, double a, double &result) { if (a >= 0) { result = sqrt(a); return SOAP_OK; } else { return soap_sender_fault(soap, "Square root of negative value", "I can only compute the square root of a non-negative value"); } } |