The client program will accept the ticker name of a stock (e.g. AOL) from the command line and will display it's current value.
#include "soapH.h" // include the generated proxy
void main(int argc, char** argv){
struct soap *soap = soap_new();
float Result; // to hold the stock's current value
char *sym; // to hold the ticker's name
if(argc > 1 ) // ticker name must be supplied on the command line
sym = argv[1];
else
return -1;
if (soap_call_ns__getQuote(soap, "services.xmethods.net/soap/", "", sym, &Result) == 0)
printf("\nCompany - %s Quote- %f \n" , sym, Result);
else
soap_print_fault(soap, stderr);
}
// Every client (and server) application MUST specify a table with namespace info.
// The first four namespaces are standard and remain unchanged until newer schema versions appear.
// The ns namespace is the delayed stock quote namespace.
// The name "ns" MUST correspond to the prefix of "ns__getQuote" function prototype (see below).
struct Namespace namespaces[] =
{
{ "SOAP-ENV", "http://schemas.xmlsoap.org/soap/envelope/" },
{ "SOAP-ENC","http://schemas.xmlsoap.org/soap/encoding/"},
{ "xsi", "http://www.w3.org/1999/XMLSchema-instance" },
{ "xsd", "http://www.w3.org/1999/XMLSchema" },
{ "ns", "urn:xmethods-delayed-quotes" },
{ NULL, NULL } // end of table
};
|
The input to our stub compiler is a specification of the name of the SOAP method (with it's optional namespace) and the data structures given as C/C++ declarations. The gSOAP wsdl2h WSDL parser creates this header file from the WSDL of the service:
wsdl2h -o quote.h http://services.xmethods.net/soap/urn:xmethods-delayed-quotes.wsdFor this example, the quote.h file contains a function prototype of the service method along with some Web service details:
//gsoap ns service style: rpc //gsoap ns service encoding: encoded //gsoap ns service namespace: urn:xmethods-delayed-quotes //gsoap ns service location: http://services.xmethods.net/soap //gsoap ns service method-action: getQuote "" int ns__getQuote(char *symbol, float *Result); |
The method name is "getQuote" and "symbol" and "Result" are argument names that correspond to the request and response XML schema definitions for the getQuote method, respectively. (Note: the prefix "ns__" to the getQuote method can be omitted but is useful as this will provide the namespace identification for invoking Xmethod's getQuote method)
To generate the sources, click here to use our SOAP C++ Stub Compiler or run the compiler on your machine by entering:
soapcpp2 quote.h(You can download the compiler). This will produce a web page containing the C/C++ sources for:
soapStub.h soapH.h soapC.cpp soapClient.cpp soapServer.cppYou need to save these sources to your local drive under the file names as indicated.
Two files are not generated but are required to build your application: stdsoap2.h, and stdsoap2.cpp. Save these files to your local drive too.
g++ -o quote quote.c soapC.cpp soapClient.cpp stdsoap2.cpp
Company - AOL Quote - 49.8(as of 6/18/2001.)