Re: Sending Struct is not working ?
Gaetano Giunta <[email protected]> Mon, 31 Mar 2008 20:34:14 +0200
| Newsgroups | gmane.text.xml.rpc.specification |
|---|---|
| Message-ID | <[email protected]> |
Sorry, why not start out with existing code? given the age of the spec,
there are a bazillion implementations ready...
>
> Hi all,
>
> I am trying to implement an xmlrpc client into a given framework. I
> have to use c/c++ for the developing the client. The struct to call
> the server has to look like this:
>
> <struct>
> <member>
> <name>source_id</name>
> <value>
> <i4>3</i4>
> </value>
> </member>
> <member>
> <name>message</name>
> <value>
> <string>Your Message Here</string>
> </value>
> </member>
> </struct>
>
> I wrote myself a client now which should - I believe so - send a
> struct like that. It is not working ! To ensure that the server works
> correctly, I build a python client - that just works fine. I do not
> know why the c/c++ client is not working. I am on that since a week...
> Any help or hint is highly appreciated !!!
> This is my code:
>
> #include <stdlib.h>
> #include <stdio.h>
> #include <iostream.h>
> #include <xmlrpc-c/base.h>
> #include <xmlrpc-c/client.h>
>
> #include <xmlrpc-c/config.h>
>
> #define NAME "Xmlrpc-c Test Client"
> #define VERSION "1.0"
>
> using namespace std;
>
> static void die_if_fault_occurred (xmlrpc_env * const envP) {
>
> if (envP->fault_occurred) {
> fprintf(stderr, "XML-RPC Fault: %s (%d)\n",
> envP->fault_string, envP->fault_code);
> exit(1);
> }
> }
>
> int main (int argc, char **argv) {
>
> xmlrpc_env env;
>
> /* Strct members - server response */
> xmlrpc_value * statusP;
> statusP = xmlrpc_int_new(&env, 0);
> xmlrpc_value * source_id_checkP;
> source_id_checkP = xmlrpc_string_new(&env,"id check foo");
> xmlrpc_value * transmit_okP;
> transmit_okP = xmlrpc_string_new(&env, "transmit foo");
> xmlrpc_value * original_messageP;
> original_messageP = xmlrpc_string_new(&env, "message foo");
> xmlrpc_value * lengthP;
> lengthP = xmlrpc_int_new(&env, 0);
> xmlrpc_value * status_textP;
> status_textP = xmlrpc_string_new(&env, "text foo");
> /* Strct */
> xmlrpc_value * resultP;
> resultP =
> xmlrpc_build_value(&env,"({%s:%d}{%s:%s}{%s:%s}{%s:%s}{%s:%d}{%s:%s})",
> "status", &statusP,
>
> "source_id_check",&source_id_checkP,
> "transmit_ok", &transmit_okP,
> "original_message",
> &original_messageP,
> "length", &lengthP,
> "status_text", &status_textP);
>
> /* Strct members - server call */
> xmlrpc_value * mysrcidP;
> mysrcidP = xmlrpc_int_new(&env, 3);
> xmlrpc_value * mymsgP;
> mymsgP = xmlrpc_string_new(&env, "My C SNEWS alarm msg");
>
> /* Strct */
> xmlrpc_value * sendStrctP;
> sendStrctP = xmlrpc_build_value(&env,"({%s:%d,%s:%s})",
> "source_id:", &mysrcidP,
> "message:", &mymsgP);
> const char * const serverUrl = "http://its-b.icecube.wisc.edu:10878/
> <http://its-b.icecube.wisc.edu:10878/>";
> const char * const methodName = "sbd.test_submission";
>
> if (argc-1 > 0) {
> fprintf(stderr, "This program has no arguments\n");
> exit(1);
> }
>
> /* Initialize our error-handling environment. */
> xmlrpc_env_init(&env);
>
> /* Start up our XML-RPC client library. */
> xmlrpc_client_init2(&env, XMLRPC_CLIENT_NO_FLAGS, NAME, VERSION,
> NULL, 0);
> die_if_fault_occurred(&env);
>
> printf("Making XMLRPC call to server url '%s' method '%s' \t",
> serverUrl, methodName);
>
> resultP = xmlrpc_client_call(&env, serverUrl,
> methodName,"({s:i,s:s})" ,"source_id", mysrcidP, "message", mymsgP);
> die_if_fault_occurred(&env);
>
> /* Dispose of our result value. */
> xmlrpc_DECREF(resultP);
> xmlrpc_DECREF(sendStrctP);
>
> /* Clean up our error-handling environment. */
> xmlrpc_env_clean(&env);
>
> /* Shutdown our XML-RPC client library. */
> xmlrpc_client_cleanup();
>
> return 0;
> }
>
> this is the error I am getting:XML-RPC Fault: Invalid struct for
> <fault> value. Value of type STRING supplied where type INT was
> expected. (-503)
> Making XMLRPC call to server url
> 'http://its-b.icecube.wisc.edu:10878/
> <http://its-b.icecube.wisc.edu:10878/>' method 'sbd.test_submission'
>
> I tried now nearly all combinations - I have no idea anymore...
>
> cheers
>
>
[Non-text portions of this message have been removed]
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/xml-rpc/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/xml-rpc/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[email protected]
mailto:[email protected]
<*> To unsubscribe from this group, send an email to:
[email protected]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/