xmlrpc_sample_add_client.cpp 974 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include <cstdlib>
  2. #include <string>
  3. #include <iostream>
  4. #include <xmlrpc-c/girerr.hpp>
  5. #include <xmlrpc-c/base.hpp>
  6. #include <xmlrpc-c/client_simple.hpp>
  7. using namespace std;
  8. int
  9. main(int argc, char **) {
  10. if (argc-1 > 0) {
  11. cerr << "This program has no arguments" << endl;
  12. exit(1);
  13. }
  14. try {
  15. string const serverUrl("http://localhost:8080/RPC2");
  16. string const methodName("sample.add");
  17. xmlrpc_c::clientSimple myClient;
  18. xmlrpc_c::value result;
  19. myClient.call(serverUrl, methodName, "ii", &result, 5, 7);
  20. int const sum = xmlrpc_c::value_int(result);
  21. // Assume the method returned an integer; throws error if not
  22. cout << "Result of RPC (sum of 5 and 7): " << sum << endl;
  23. } catch (exception const& e) {
  24. cerr << "Client threw error: " << e.what() << endl;
  25. } catch (...) {
  26. cerr << "Client threw unexpected error." << endl;
  27. }
  28. return 0;
  29. }