Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Client/Server SOAP library written in C

Status
Not open for further replies.

snowdrop

Programmer
Joined
Feb 9, 2004
Messages
1
Location
DE
Hi folks,
try the SOAP library written in C. With csoap you can also implement a SOAP
server in C. This library depends on libxml2.

Homepage: Release 1.0.0


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

static const char *url = "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;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top