Soap Client Library

A very basic example program using the Soap Client Library, so it can send a request to and receive a response from a Web Services looks like this:

#include <prolinga/SoapClient.hpp>

int main()
{
        /* Create a request */
        xmlDocPtr docReq;
        xmlNodePtr curReq;
        docReq = xmlNewDoc((const xmlChar *)"1.0");
        docReq->children = xmlNewDocNode(docReq, NULL, (const xmlChar *)"ProLinga", NULL);
        curReq = xmlDocGetRootElement(docReq);
        xmlNewTextChild (curReq, NULL, (const xmlChar *)"String", (const xmlChar *)"This is a simple request.");

        /* Send of request and get response */
        PlSoapClient sclient;
        xmlDocPtr docRes;
        docRes = sclient.soapCall(docReq, "http://localhost:8020",0);

        /* Print response */
        xmlNodePtr curRes;
        xmlBufferPtr bufRes;
        bufRes = xmlBufferCreate();
        curRes = xmlDocGetRootElement(docRes);
        xmlNodeDump(bufRes, docRes, curRes, 0, 1);
        printf("%s\n", (char *)xmlBufferContent(bufRes));
        xmlBufferFree(bufRes);

	/* Free */
	xmlFreeDoc(docReq);
	xmlFreeDoc(docRes);

        /* Return */
        return 0;
}

This function creates a small XML document and sends that to TCP port 8020 of localhost. The request gets processed and a response comes back in XML format. This is then printed to the standard output.

To test these 2 examples, start the service logic first in one terminal screen and then execute the client logic from another terminal screen.

To compile the program, use the following command:

g++ soap_c_test.cpp -o soap_c_test `pkg-config --cflags --libs prolinga-soapclient`

Note

You may need to set the environment variable PKG_CONFIG_PATH to point to the directory where prolinga-soapclient.pc is located. By default this is directory /usr/local/lib/pkgconfig on GNU/Linux for example.

You can also use a more traditional command as:

g++ soap_c_test.cpp -o soap_c_test -I/usr/local/include/ -L/usr/local/lib -lprolingasoapclient -lxml2 -lz

The Soap library prolingasoap contains both the Service as the Client class, so client calls can be made as well.