1 /* A simple synchronous XML-RPC client written in C, as an example of
2 an Xmlrpc-c client. This invokes the sample.add procedure that the
3 Xmlrpc-c example server.c server provides. I.e. it adds to numbers
4 together, the hard way.
10 #include <xmlrpc-c/base.h>
11 #include <xmlrpc-c/client.h>
13 #include "config.h" /* information about this build environment */
15 #define NAME "Xmlrpc-c Test Client"
19 die_if_fault_occurred (xmlrpc_env *env) {
20 if (env->fault_occurred) {
21 fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
22 env->fault_string, env->fault_code);
31 const char ** const argv ATTR_UNUSED) {
36 char * const serverUrl = "http://localhost:8080/RPC2";
37 char * const methodName = "sample.add";
40 fprintf(stderr, "This program has no arguments\n");
44 /* Initialize our error-handling environment. */
45 xmlrpc_env_init(&env);
47 /* Start up our XML-RPC client library. */
48 xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION, NULL, 0);
49 die_if_fault_occurred(&env);
51 printf("Making XMLRPC call to server url '%s' method '%s' "
53 "of 5 and 7...\n", serverUrl, methodName);
55 /* Make the remote procedure call */
56 result = xmlrpc_client_call(&env, serverUrl, methodName,
57 "(ii)", (xmlrpc_int32) 5, (xmlrpc_int32) 7);
58 die_if_fault_occurred(&env);
60 /* Get our sum and print it out. */
61 xmlrpc_read_int(&env, result, &sum);
62 die_if_fault_occurred(&env);
63 printf("The sum is %d\n", sum);
65 /* Dispose of our result value. */
66 xmlrpc_DECREF(result);
68 /* Clean up our error-handling environment. */
69 xmlrpc_env_clean(&env);
71 /* Shutdown our XML-RPC client library. */
72 xmlrpc_client_cleanup();