From 686e18007c265bea4a3170b39ec5a7f72b6a6714 Mon Sep 17 00:00:00 2001 From: snowdrop Date: Fri, 6 Feb 2004 07:23:58 +0000 Subject: initial import --- doc/tutorial.xml | 289 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 289 insertions(+) create mode 100755 doc/tutorial.xml (limited to 'doc') diff --git a/doc/tutorial.xml b/doc/tutorial.xml new file mode 100755 index 0000000..60ef598 --- /dev/null +++ b/doc/tutorial.xml @@ -0,0 +1,289 @@ + +
+ + + cSOAP Implementation Guide $Revision: 1.1 $ + FerhatAyaz + 2004csoap + + +
+ Introduction + + + This document gives you information about how to use the cSOAP API in your applications. + + +
+ +
+Implementing a simple SOAP Client + + +A simple SOAP client + + + + + + + + + + + + + + + +/* FILE: simpleclient.c */ +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; +} + + + + + + + + + First we create a SOAP envelope (SoapEnv) using the + soap_env_new_with_method(). This creates the + following SOAP envelope. + + + +Generated SOAP envelope + + + + + + + + + + + +]]> + + + + + + + + +soap_env_add_item() will add a xml parameter to the envelope like follows + + +Added "name" parameter + + + + + + Jonny B. Good + + + + + +]]> + + + + + + + Now we can send our soap call using soap_client_invoke(). The third argument +is the SoapAction header value. The result is also a SOAP envelope. +soap_client_invoke() will return always a SoapEnv object. It is +the result SOAP envelope or a fault object. + + + + + + res->root is always the root xml element of the result SOAP envelope + and res->root->doc points always to the xmlDocPtr. + soap_xml_doc_print() is a helper function to print out a xml document. + + + + +Free both envelope objects + + + + + + + + +
+ + +
+Implementing a simple SOAP Server + + +A simple SOAP server + + + + + + + + + + + + + + +/* FILE: simpleserver.c */ + +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; +} + + + + + + + +Init server with commandline arguments. The init argument at this time is only + -NHTTPport <portnum> . + + + + +Create a router + + + + + Register the service function say_hello under the methodname sayHello a + and urn urn:examples at the router object router. + + + + +Register the router under the context /csoapserver. +Now your service is avaiable at the address http://localhost:port/csoapserver. + + +Default http port is 10000 + + + + + + Enter the http server loop. after calling soap_server_run() , + the application will enter the http server (nanohttp) loop. + + + + + + Free the router. + + + + + + Destroy and free soap server stuff. + + + + + + + + +
+ +
+Compiling SOAP applications + + + csoap has pkg-config support. So you can can use +pkg-config with libcsoap parameter. + + + +An example Makefile + + + + + + + +
+ +
-- cgit v1.1-32-gdbae