Howto write a SOAP client

Table of contents

Client initialization

 static char *url = "http://localhost:10000/csoapserver";
 static char *urn = "urn:examples";
 static char *method = "sayHello";

 int * main(int argc, char **argv)
 {
   struct SoapCtx *request;
   struct SoapCtx *response;
   herror_t err;

   if ((err = soap_client_init_args(argc, argv)) != H_OK)
   {
     printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err));
     herror_release(err);
     exit(1);
   }

Envelope creation

   if ((err = soap_ctx_new_with_method(urn, method, &request)) != H_OK)
   {
     printf("%s():%s [%d]\n", herror_func(err), herror_message(err), herror_code(err));
     herror_release(err);
     soap_client_destroy();
     exit(1);
   }

   soap_env_add_item(request->env, "xsd:string", "name", "Jonny B. Good");

Invocation

   if ((err = soap_client_invoke(request, &response, url, "")) != H_OK)
   {
     printf("[%d] %s(): %s\n", herror_code(err), herror_func(err), herror_message(err));
     herror_release(err);
     soap_ctx_free(request);
     soap_client_destroy();
     exit(1);
   }

Printout result

   printf("**** received from \"%s\" ****\n", soap_addressing_get_from_address_string(response->env));
   xmlDocFormatDump(stdout, response->env->root->doc, 1);

Request cleanup

   soap_ctx_free(response);
   soap_ctx_free(request);

Client cleanup

   soap_client_destroy();

   exit(0);
 }

Generated on Thu Jan 25 23:36:01 2007 for csoap by  doxygen 1.4.6