[xml] SOAP library using libxml2



Hi folks,
look for the client/server SOAP library written in the C programming language for C applications using libxml2.


Homepage: http://csoap.sourceforge.net



/********************************************************/
Example client using CSOAP

static const char *url = "http://csoap.sourceforge.net/cgi-bin/csoapserver";;
static const char *urn = "urn:examples";
static const char *method = "sayHello";

int main(int argc, char *argv[])
{
SoapEnv *env, *res;

 env = soap_env_new_with_method(urn, method);

 soap_env_add_item(env, "xsd:string",
        "name", "Jonny B. Good");
 res = soap_client_invoke(env, url , "");

 soap_xml_doc_print(res->root->doc);

 soap_env_free(res);
 soap_env_free(env);

return 0;
}

/********************************************************/
Example server using CSOAP

/**
        FUNCTION: say_hello()
        DESCRIPTION: The SOAP Server service function.
        URN: urn:examples
        METHOD: sayHello
*/
SoapEnv* say_hello(SoapEnv *request)
{

SoapEnv *env;
xmlNodePtr method, node;
char *name;

env = soap_env_new_with_response(request);

method = soap_env_get_method(request);
node = soap_xml_get_children(method);

while (node) {

  name = (char*)xmlNodeListGetString(node->doc,
                node->xmlChildrenNode, 1);
  if (!name) continue;

  soap_env_add_itemf(env,"xsd:string", "echo", "Hello '%s'", name);

  xmlFree((xmlChar*)name);

  node = soap_xml_get_next(node);
}

return env;
}

/**
        FUNCTION: main()
        DESCRIPTION: Register and run soap server
*/
int main(int argc, char *argv[])
{

SoapRouter *router;

 if (!soap_server_init_args(argc, argv)) {
  return 0;
}

 router = soap_router_new();

soap_router_register_service(router, say_hello, "sayHello", "urn: examples");
 soap_server_register_router(router, "/csoapserver");

 soap_server_run();

 soap_router_free(router);
 soap_server_destroy();

return 0;
}







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]