您的位置:首页 > 编程语言 > C语言/C++

VC中使用XMLRPC提供接口(XMLPRC++)

2012-07-19 15:04 183 查看
首先从XMLRPC官网http://www.xmlrpc.com/,或者http://sourceforge.net/projects/xmlrpcpp/网站下载XMLRPC++0.7。解压。解压之后必须用vc6.0来运行编译,会生成一个xmlrpc.lib的文件,这个文件即为下面所需要用到的。

1.熟悉XMLRPC
可以运行xmlrpc.dsw工程中的的例子。阅读HelloServer、HelloClient工程的源码,可以大概了解XMLRPC如何使用。
2. 传递结构体的例子 将src文件夹文件复制到client工程目录下。 在Project->settings->c/c++->Category->Preprocesser->Additionalinclude directions添加附加文件路径“src”。
在Project->settings->Link->Category->General->Object/LibraryModules中添加xmlrpc.libWs2_32.lib两个lib,
并将Project->settings->c/c++->Category->CodeGeneration->Use Run time Library 修改为MultiThreaded DLL或者Debug MultiThreaded DLL。 1、客户端Client #include "stdafx.h" #include "XmlRpc.h" #include <iostream> using namespace XmlRpc; int main(int argc, char* argv[]) { constchar *server = "localhost";
const int port= 8085;
const char *uri= NULL;
XmlRpcValueargs, res;
XmlRpcClientc(server, port, uri);
c.execute("HelloWorld",args, res);//HelloWorld为服务器端定义的方法名;args为传递给服务器端的参数;res为收到的服务器返回的结果。 return0; }

2、服务器端Server #include "stdafx.h" #include "XmlRpc.h" #include <iostream> #include <stdlib.h> using namespace XmlRpc; // The server XmlRpcServer s; // No arguments, result is "Hello". class HelloWorld : public XmlRpcServerMethod { public: HelloWorld(XmlRpcServer* s) : XmlRpcServerMethod("HelloWorld",s) {} void execute(XmlRpcValue¶ms, XmlRpcValue& result) { //此处可随意添加自己想执行的函数和代码,params即是客户端传递过来的参数,result为返回给客户端的结果,结果可随意定义。 } } helloworld(&s); // This constructor registers the method with theserver int main(int argc, char* argv[]) { XmlRpcLogHandler::setVerbosity(1000); intport = 8085;//要与客户端一致 XmlRpc::setVerbosity(5); // Create the server socket on the specified port s.bindAndListen(port); // Enable introspection s.enableIntrospection(true); // Wait for requests indefinitely s.work(-1.0); return 0; }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  string library constructor