|  | Home | Documentation | Code Example 1: Finding a service updated by Robert van Engelen |

Code Example 1: Finding a service

This example shows you how to find Web services. In this case, the example finds Web services with names that begin with the word "magic".

#include "inqH.h"
int main(int argc, char **argv)
{
char *search_string = "magic";
if (argc > 1)
search_string = argv[1];
// Create a gSOAP context
struct soap *soap = soap_new();
// Create an object to find a business
uddi2__find_USCOREservice fs(soap, search_string);
// Send the request
uddi2__serviceList *sl = fs.send("http://uddi.xmethods.net/inquire");
// Check if result is OK
if (!sl)
soap_print_fault(soap, stderr);
// If OK, report the service name(s) and unique identification keys
else if (sl->serviceInfos)
{
std::cout << "Search results on " << search_string << ":" << std::endl << std::endl;
for (std::vector<uddi2__serviceInfo*>::const_iterator si = sl->serviceInfos->serviceInfo.begin(); si != sl->serviceInfos->serviceInfo.end(); ++si)
{
// Report serviceKey and businessKey
std::cout << "serviceKey=" << (*si)->serviceKey << std::endl << "businessKey=" << (*si)->businessKey << std::endl;
// Report names
for (std::vector<uddi2__name*>::const_iterator n = (*si)->name.begin(); n != (*si)->name.end(); ++n)
std::cout << "name=" << (*n)->__item << std::endl;
std::cout << std::endl;
}
}
// Remove deserialized objects
soap_destroy(soap);
// Remove temporary data
soap_end(soap);
// Detach and free context
soap_done(soap);
free(soap);
return 0;
}
uddi2__find_USCOREservice
Schema urn:uddi-org:api_v2:"find_service".
Definition uddi_v2.h:2580
uddi2__serviceInfos::serviceInfo
std::vector< uddi2__serviceInfo * > serviceInfo
Vector of uddi2__serviceInfo* with length 0..unbounded.
Definition uddi_v2.h:2250
uddi2__serviceList
Schema urn:uddi-org:api_v2:"serviceList".
Definition uddi_v2.h:3102
uddi2__serviceList::serviceInfos
uddi2__serviceInfos * serviceInfos
Element reference "urn:uddi-org:api_v2":serviceInfos.
Definition uddi_v2.h:3104

To compile:

- wsdl2h -tuddi2-typemap.dat inquire_v2.wsdl
- soapcpp2 -I.. -pinq inquire_v2.h
- g++ -DWITH_NONAMESPACES -I.. -o example1 example1.cpp inquire_v2.cpp inqC.cpp inqClient.cpp ../stdsoap2.cpp