xmlrpc++谁用过?

大爷想要时光机 2009-07-08 04:26:12
怎么给远程调用methodCall加参数呢,也就是客户端的接口execute中,第二个参数是给这个xmlrpc调用带上参数的,参数有数组和结构体,利用XmlRpcValue这个类来传,具体是怎么传递呢?
...全文
179 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
blueice12 2011-06-05
  • 打赏
  • 举报
回复
XmlRpcValue可以当做数据或者结构来用,支持[]操作符。
例如:params可以使用
params[0]["Name"] = "ZhangSan";
params[0]["Age"]=12;

不过我用测试程序没问题,但是把服务器放在多线程程序中的非GUI线程运行,就不稳定,有时候能行,有时候不行,暂时还没解决。
  • 打赏
  • 举报
回复
http://xmlrpcplus-pplus-p.sourcearchive.com/documentation/0.7plus-pcvs20040713/dir_fac05448057e67e857b9e6566979f567.html
目录:
test Directory Reference

Files
file FileClient.cpp [code]
file HelloClient.cpp [code]
file HelloServer.cpp [code]
file TestBase64Client.cpp [code]
file TestBase64Server.cpp [code]
file TestEGroupwareSSLClient.cpp [code]
file TestValues.cpp [code]
file TestValuesWin32.cpp [code]
file TestXml.cpp [code]
file Validator.cpp [code]

其中FileClient.cpp的code为:
00001 // FileClient.cpp : A simple xmlrpc client. Usage: FileClient serverHost serverPort xmlfile
00002 // Reads an xmlrpc request from the specified xmlfile and calls the method on the server.
00003 //
00004 // Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib on windows)
00005
00006 #include "XmlRpc.h"
00007 #include <iostream>
00008 #include <fstream>
00009 #include <stdlib.h>
00010
00011 using namespace XmlRpc;
00012
00013 std::string parseRequest(std::string const& xml, XmlRpcValue& params);
00014
00015
00016 int main(int argc, char* argv[])
00017 {
00018 if (argc != 4) {
00019 std::cerr << "Usage: FileClient serverHost serverPort requestXmlFile\n";
00020 return -1;
00021 }
00022 int port = atoi(argv[2]);
00023
00024 XmlRpc::setVerbosity(5);
00025 XmlRpcClient c(argv[1], port);
00026
00027 //
00028 std::ifstream infile(argv[3]);
00029 if (infile.fail()) {
00030 std::cerr << "Could not open file '" << argv[3] << "'.\n";
00031 return -1;
00032 }
00033
00034 // Suck in the file. This is a one-liner in good compilers (which vc++ 6 is not)...
00035 infile.seekg(0L, std::ios::end);
00036 long nb = infile.tellg();
00037 infile.clear();
00038 infile.seekg(0L);
00039 char* b = new char[nb+1];
00040 infile.read(b, nb);
00041 b[nb] = 0;
00042
00043 std::cout << "Read file.\n";
00044
00045 // Find the methodName and parse the params
00046 std::string s(b);
00047 XmlRpcValue params;
00048 std::string name = parseRequest(s, params);
00049
00050 if (name.empty()) {
00051 std::cerr << "Could not parse file\n";
00052 return -1;
00053 }
00054
00055 for (;;) {
00056 XmlRpcValue result;
00057 std::cout << "Calling " << name << std::endl;
00058 if (c.execute(name.c_str(), params, result))
00059 std::cout << result << "\n\n";
00060 else
00061 std::cout << "Error calling '" << name << "'\n\n";
00062 std::cout << "Again? [y]: ";
00063 std::string ans;
00064 std::cin >> ans;
00065 if (ans != "" && ans != "y") break;
00066 }
00067
00068 return 0;
00069 }
00070
00071
00072 //
00073 std::string
00074 parseRequest(std::string const& xml, XmlRpcValue& params)
00075 {
00076 const char METHODNAME_TAG[] = "<methodName>";
00077 const char PARAMS_TAG[] = "<params>";
00078 const char PARAMS_ETAG[] = "</params>";
00079 const char PARAM_TAG[] = "<param>";
00080 const char PARAM_ETAG[] = "</param>";
00081
00082 int offset = 0; // Number of chars parsed from the request
00083
00084 std::string methodName = XmlRpcUtil::parseTag(METHODNAME_TAG, xml, &offset);
00085 XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed methodName %s.", methodName.c_str());
00086
00087 if (! methodName.empty() && XmlRpcUtil::findTag(PARAMS_TAG, xml, &offset))
00088 {
00089 int nArgs = 0;
00090 while (XmlRpcUtil::nextTagIs(PARAM_TAG, xml, &offset)) {
00091 std::cout << "Parsing arg " << nArgs+1 << std::endl;
00092 XmlRpcValue arg(xml, &offset);
00093 if ( ! arg.valid()) {
00094 std::cerr << "Invalid argument\n";
00095 return std::string();
00096 }
00097 std::cout << "Adding arg " << nArgs+1 << " to params array." << std::endl;
00098 params[nArgs++] = arg;
00099 (void) XmlRpcUtil::nextTagIs(PARAM_ETAG, xml, &offset);
00100 }
00101
00102 XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed %d params.", nArgs);
00103
00104 (void) XmlRpcUtil::nextTagIs(PARAMS_ETAG, xml, &offset);
00105 }
00106
00107 return methodName;
00108 }


可以直接调用!
希望能对你有所帮助,谢谢!

  • 打赏
  • 举报
回复
00001 // FileClient.cpp : A simple xmlrpc client. Usage: FileClient serverHost serverPort xmlfile
00002 // Reads an xmlrpc request from the specified xmlfile and calls the method on the server.
00003 //
00004 // Link against xmlrpc lib and whatever socket libs your system needs (ws2_32.lib on windows)
00005
00006 #include "XmlRpc.h"
00007 #include <iostream>
00008 #include <fstream>
00009 #include <stdlib.h>
00010
00011 using namespace XmlRpc;
00012
00013 std::string parseRequest(std::string const& xml, XmlRpcValue& params);
00014
00015
00016 int main(int argc, char* argv[])
00017 {
00018 if (argc != 4) {
00019 std::cerr << "Usage: FileClient serverHost serverPort requestXmlFile\n";
00020 return -1;
00021 }
00022 int port = atoi(argv[2]);
00023
00024 XmlRpc::setVerbosity(5);
00025 XmlRpcClient c(argv[1], port);
00026
00027 //
00028 std::ifstream infile(argv[3]);
00029 if (infile.fail()) {
00030 std::cerr << "Could not open file '" << argv[3] << "'.\n";
00031 return -1;
00032 }
00033
00034 // Suck in the file. This is a one-liner in good compilers (which vc++ 6 is not)...
00035 infile.seekg(0L, std::ios::end);
00036 long nb = infile.tellg();
00037 infile.clear();
00038 infile.seekg(0L);
00039 char* b = new char[nb+1];
00040 infile.read(b, nb);
00041 b[nb] = 0;
00042
00043 std::cout << "Read file.\n";
00044
00045 // Find the methodName and parse the params
00046 std::string s(b);
00047 XmlRpcValue params;
00048 std::string name = parseRequest(s, params);
00049
00050 if (name.empty()) {
00051 std::cerr << "Could not parse file\n";
00052 return -1;
00053 }
00054
00055 for (;;) {
00056 XmlRpcValue result;
00057 std::cout << "Calling " << name << std::endl;
00058 if (c.execute(name.c_str(), params, result))
00059 std::cout << result << "\n\n";
00060 else
00061 std::cout << "Error calling '" << name << "'\n\n";
00062 std::cout << "Again? [y]: ";
00063 std::string ans;
00064 std::cin >> ans;
00065 if (ans != "" && ans != "y") break;
00066 }
00067
00068 return 0;
00069 }
00070
00071
00072 //
00073 std::string
00074 parseRequest(std::string const& xml, XmlRpcValue& params)
00075 {
00076 const char METHODNAME_TAG[] = "<methodName>";
00077 const char PARAMS_TAG[] = "<params>";
00078 const char PARAMS_ETAG[] = "</params>";
00079 const char PARAM_TAG[] = "<param>";
00080 const char PARAM_ETAG[] = "</param>";
00081
00082 int offset = 0; // Number of chars parsed from the request
00083
00084 std::string methodName = XmlRpcUtil::parseTag(METHODNAME_TAG, xml, &offset);
00085 XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed methodName %s.", methodName.c_str());
00086
00087 if (! methodName.empty() && XmlRpcUtil::findTag(PARAMS_TAG, xml, &offset))
00088 {
00089 int nArgs = 0;
00090 while (XmlRpcUtil::nextTagIs(PARAM_TAG, xml, &offset)) {
00091 std::cout << "Parsing arg " << nArgs+1 << std::endl;
00092 XmlRpcValue arg(xml, &offset);
00093 if ( ! arg.valid()) {
00094 std::cerr << "Invalid argument\n";
00095 return std::string();
00096 }
00097 std::cout << "Adding arg " << nArgs+1 << " to params array." << std::endl;
00098 params[nArgs++] = arg;
00099 (void) XmlRpcUtil::nextTagIs(PARAM_ETAG, xml, &offset);
00100 }
00101
00102 XmlRpcUtil::log(3, "XmlRpcServerConnection::parseRequest: parsed %d params.", nArgs);
00103
00104 (void) XmlRpcUtil::nextTagIs(PARAMS_ETAG, xml, &offset);
00105 }
00106
00107 return methodName;
00108 }


Walf_ghoul 2009-07-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 jimmy_w 的回复:]
引用 1 楼 Walf_ghoul 的回复:

路过,帮顶。。。


白高兴一场
[/Quote]

while(true)
{
cout<<"I am sorry...."<<endl;
}
lingyin55 2009-07-08
  • 打赏
  • 举报
回复
Fleeboy 2009-07-08
  • 打赏
  • 举报
回复
java的用过,感觉并不难。
C++的还在学习中
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 jimmy_w 的回复:]
引用 5 楼 jindan_jinming 的回复:
http://xmlrpcplus-pplus-p.sourcearchive.com/documentation/0.7plus-pcvs20040713/classXmlRpc_1_1XmlRpcClient.html
里面哪个接口不清楚的话直接点里面的链接即可!

希望能对你有所帮助,谢谢!



这个基本上没用,我看的就是官方的文档,只有类的声明和成员函数的原型,没有demo,不知道怎么调用
[/Quote]

http://xmlrpcplus-pplus-p.sourcearchive.com/documentation/0.7plus-pcvs20040713/dir_fac05448057e67e857b9e6566979f567.html
这个全都是test的文件,也可以当demo来用!
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jindan_jinming 的回复:]
http://xmlrpcplus-pplus-p.sourcearchive.com/documentation/0.7plus-pcvs20040713/classXmlRpc_1_1XmlRpcClient.html
里面哪个接口不清楚的话直接点里面的链接即可!

希望能对你有所帮助,谢谢!
[/Quote]

这个基本上没用,我看的就是官方的文档,只有类的声明和成员函数的原型,没有demo,不知道怎么调用
K_s_G 2009-07-08
  • 打赏
  • 举报
回复
很高深
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 jindan_jinming 的回复:]
http://xmlrpcplus-pplus-p.sourcearchive.com/documentation/0.7plus-pcvs20040713/classXmlRpc_1_1XmlRpcClient.html
里面哪个接口不清楚的话直接点里面的链接即可!

希望能对你有所帮助,谢谢!
[/Quote]
摘取一下:
bool XmlRpcClient::execute  ( const char *  method,  
XmlRpcValue const & params,
XmlRpcValue & result
)

Execute the named procedure on the remote server.

Parameters:
method The name of the remote procedure to execute
params An array of the arguments for the method
result The result value to be returned to the client

Returns:
true if the request was sent and a result received (although the result might be a fault).
Currently this is a synchronous (blocking) implementation (execute does not return until it receives a response or an error). Use isFault() to determine whether the result is a fault response.
Definition at line 165 of file XmlRpcClient.cpp.

References XmlRpc::XmlRpcValue::clear(), XmlRpc::XmlRpcUtil::log(), and XmlRpc::XmlRpcDispatch::work().

00166 {
00167 XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s (_connectionState %d).", method, _connectionState);
00168
00169 // This is not a thread-safe operation, if you want to do multithreading, use separate
00170 // clients for each thread. If you want to protect yourself from multiple threads
00171 // accessing the same client, replace this code with a real mutex.
00172 if (_executing)
00173 return false;
00174
00175 _executing = true;
00176 ClearFlagOnExit cf(_executing);
00177
00178 _sendAttempts = 0;
00179 _isFault = false;
00180
00181 if ( ! setupConnection())
00182 return false;
00183
00184 if ( ! generateRequest(method, params))
00185 return false;
00186
00187 result.clear();
00188 double msTime = -1.0; // Process until exit is called
00189 _disp.work(msTime);
00190
00191 if (_connectionState != IDLE || ! parseResponse(result))
00192 return false;
00193
00194 XmlRpcUtil::log(1, "XmlRpcClient::execute: method %s completed.", method);
00195 _response = "";
00196 return true;
00197 }


  • 打赏
  • 举报
回复
http://xmlrpcplus-pplus-p.sourcearchive.com/documentation/0.7plus-pcvs20040713/classXmlRpc_1_1XmlRpcClient.html
里面哪个接口不清楚的话直接点里面的链接即可!

希望能对你有所帮助,谢谢!
asksgp 2009-07-08
  • 打赏
  • 举报
回复
太高级了,没听过
大前置 2009-07-08
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Walf_ghoul 的回复:]

路过,帮顶。。。
[/Quote]

无功不受禄。 。。
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 Walf_ghoul 的回复:]

路过,帮顶。。。
[/Quote]
白高兴一场
Walf_ghoul 2009-07-08
  • 打赏
  • 举报
回复

路过,帮顶。。。
本门课程是带大家进入微服务领域入门的课程,很适合新手小白学习的课程。1: 什么是rpcRPC(Remote Procedure Call)是函数对函数的远程调用,传输协议tcp,http,主要是基于xml,json序列化协议(这里的序列化协议是对数据编解码的方式),项目中我们真正用到的是grpc,grpc是一个框架,基于http2.0的长链接,性能有所改进,重要的是grpc用的是Google开源的protobuf序列化协议,它比json,xml性能更快,在压缩数据方面也更小。总之我们选择grpc最主要的有两点:1:支持跨语言开发(如python,golang,java)2:  grpc首先是一个框架,封装rpc,让程序员只关注代码逻辑即可 2: 为什么用grpc,而不用flask,django,tornado,即http协议?1:http的调用是根据url的(即restful),它跟rpc的调用最大的区别就是这里,rpc的调用,你就像调用一个本地函数一样简单,而且微服务,分布式也是从rpc开始的,学好rpc对以后做好分布式会更有帮助,其实go语言和python语言里都有rpc(如xmlrpc,jsonrpc,zerorpc),我们之所以学习go语言里的rpc是因为go语言的rpc相对更加灵活,go语言本身也支持高并发,这一点对于分布式来说更好。2:其次http协议,用过flask框架的人都知道,请求一次数据后就断开,而grpc基于http2.0,它不但可以保持长链接,传输效率也更高,使用方面,因为http2.0相当于tcp一样使用,现在很多大厂也都开始用http2.0了。http2.0相比http的优势很明显,头部压缩,分流,针对tcp的多路复用。所以基于http2.0的grpc无论从生态和性能方面都更好。 这张图是一个gRPC相关的架构图,同学们可以通过这张图了解gRPC在项目中的使用。

24,854

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧