User Tools

Site Tools


Pure C SOAP client example

Library csoap is here http://csoap.sourceforge.net

soapclient.c
#include <nanohttp/nanohttp-logging.h>
#include <libcsoap/soap-client.h>
 
static const char *url = "http://rpi2.unix7.org/soap/asterisk.pl";
static const char *urn = "http://rpi2.unix7.org";
static const char *method = "Hello";
 
int
main(int argc, char *argv[])
{
  SoapCtx *ctx, *ctx2;
  herror_t err;
 
  /* log_set_level(HLOG_VERBOSE); */
  err = soap_client_init_args(argc, argv);
  if (err != H_OK)
  {
    log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
               herror_code(err));
    herror_release(err);
    return 1;
  }
 
  err = soap_ctx_new_with_method(urn, method, &ctx);
  if (err != H_OK)
  {
    log_error4("%s():%s [%d]", herror_func(err), herror_message(err),
               herror_code(err));
    herror_release(err);
    return 1;
  }
 
  soap_env_add_item(ctx->env, "xsd:string", "name", "Jonny B. Good");
 
  if (argc > 1)
    err = soap_client_invoke(ctx, &ctx2, argv[1], "");
  else
    err = soap_client_invoke(ctx, &ctx2, url, "");
 
  if (err != H_OK)
  {
    log_error4("[%d] %s(): %s ", herror_code(err), herror_func(err),
               herror_message(err));
    herror_release(err);
    soap_ctx_free(ctx);
    return 1;
  }
 
  soap_xml_doc_print(ctx2->env->root->doc);
  soap_ctx_free(ctx2);
  soap_ctx_free(ctx);
 
  soap_client_destroy();
  return 0;
}

First PagePrevious PageBack to overviewNext PageLast Page