xmlrpc_clnt_example.cpp

Go to the documentation of this file.
00001 
00002  //
00003  // XMLStorage XML-RPC client example
00004  //
00005  // Copyright (c) 2009 Martin Fuchs <martin-fuchs@gmx.net>
00006  //
00007 
00008 
00009 /*
00010 
00011   All rights reserved.
00012 
00013   Redistribution and use in source and binary forms, with or without
00014   modification, are permitted provided that the following conditions are met:
00015 
00016   * Redistributions of source code must retain the above copyright
00017     notice, this list of conditions and the following disclaimer.
00018   * Redistributions in binary form must reproduce the above copyright
00019     notice, this list of conditions and the following disclaimer in
00020     the documentation and/or other materials provided with the
00021     distribution.
00022 
00023   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00024   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00025   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00026   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00027   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00028   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00029   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00030   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00031   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00032   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033   POSSIBILITY OF SUCH DAMAGE.
00034 
00035 */
00036 
00037 #include "httpclnt.h"
00038 
00039 #include <iostream>
00040 
00041 
00042 static void client_test()
00043 {
00044     const char* url = "http://localhost:8080/";
00045 
00046     XMLRPCClient client(url, _T("XMLStorage XMLRPC"));
00047 
00048      // allow persistent HTTP connections
00049 //  client.enable_extensions();
00050 
00051     ISODate start;
00052 
00053     for(int i=0; i<1; ++i) {
00054         XMLRPCResult& result1 = client.call(url, XMLRPCCall("examples.getStateName") % 17);
00055         cout << result1.get_string() << endl;
00056 
00057         XMLRPCResult& result2 = client.call(url, XMLRPCCall("Calculator.add") % 17 % 4);
00058         cout << result2.get_double() << endl;
00059 
00060         XMLRPCResult& result3 = client.call(url, XMLRPCCall("Calculator.subtract") % 17 % 4);
00061         cout << result3.get_int() << endl;
00062 
00063         XMLRPCResult& result4 = client.call(url, XMLRPCCall("examples.getArray") % 41 % "test" % 3.14 % false);
00064         const XMLRPCArray& arr = result4.get_array();
00065         for(XMLRPCArray::const_iterator it_arr=arr.begin(); it_arr!=arr.end(); ++it_arr)
00066             cout << *it_arr << endl;
00067 
00068         XMLRPCResult& result5 = client.call(url, XMLRPCCall("examples.getStruct") % "A" % "B" % "C");
00069         const XMLRPCStruct& str = result5.get_struct();
00070         for(XMLRPCStruct::const_iterator it_str=str.begin(); it_str!=str.end(); ++it_str)
00071             cout << it_str->first << "=" << it_str->second << endl;
00072 
00073         XMLRPCResult& result6 = client.call(url, XMLRPCCall("examples.transferBinary") % Binary("Hello binary world", 18));
00074         cout << result6.get_string() << endl;
00075 
00076         XMLRPCResult& result7 = client.call(url, XMLRPCCall("examples.readBinary"));
00077         cout << result7.get_binary().str() << endl;
00078 
00079         XMLRPCResult& last_result = client.call(url, XMLRPCCall("examples.getTime"));
00080         ISODate now = last_result.get_date();
00081         cout << now.str() << endl;
00082 
00083         XMLRPCResult& result_time = client.call(url, XMLRPCCall("Calculator.subtract") % now % start);
00084         cout << result_time.get_int() << " Sekunden Laufzeit" << endl;
00085     }
00086 }
00087 
00088 
00089 int main()
00090 {
00091     try {
00092         client_test();
00093     } catch(exception& e) {
00094         cerr << endl << e.what() << endl;
00095     }
00096 
00097     return 0;
00098 }