[
Lists Home |
Date Index |
Thread Index
]
- To: xml-dev@lists.xml.org
- Subject: SOAP library written in C
- From: Ferhat Ayaz <ayaz@jprogrammer.net>
- Date: Thu, 5 Feb 2004 22:35:59 +0100
- In-reply-to: <20040205213313.GG1853@debian> (from ayaz@jprogrammer.net on Thu, Feb 05, 2004 at 22:33:13 +0100)
- References: <20040205213313.GG1853@debian>
Hi folks,
try the SOAP library written in C. You can also implement a SOAP
server in C. This library depends on 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;
}
|