Listing 8

// file: service.cpp
#include "soapH.h"
#include "CollisionService.nsmap"
main()
{  // set up a gSOAP runtime context
   struct soap *soap = soap_new();
   // bind to port 8080 (service endpoint)
   soap_bind(soap, NULL, 8080, 100);
   // server loop
   for (;;)
   {  // accept request
      soap_accept(soap);
      if (soap->error != SOAP_OK)
      {  soap_print_fault(soap, stderr);
         break;
      }
      // dispatch the client request
      if (soap_serve(soap) != SOAP_OK)
         soap_print_fault(soap, stderr);
     // remove class instances
     soap_destroy(soap);
     // clean up
     soap_end(soap);
   }
   // detach gSOAP context
   soap_done(soap);
   // dealloc gSOAP context
   free(soap);
}
// service operation
int cws__detect_collisions(struct soap *soap, Objects objects, int& hits)
{  if (objects.empty())
   { char *msg = soap_malloc(soap, 256);
   sprintf(msg, "Empty collection from IP=%d.%d.%d.%d", 
      (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, 
        (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
     return soap_sender_fault(soap, msg, NULL);
   }
   hits = objects.collisions();
   return SOAP_OK;
}