C# Xmlrpc

服务器程序用socket听5010端口,接收一个RPC调用叫"Ping",你需要实现callPing()
using System;
using System.Collections.Generic;
using System.Text;
using XmlRpcLib;

namespace XMLRPCServer1
{
     class Program
     {
         public static XmlRpcServer Server;
         static void Main(string[] args)
         {
             Server = new XmlRpcServer("127.0.0.1", 5010);
             Server.Start();
             Server.RegisterMethod("Ping", new dCallMethod(callPing));
         }

         static GbxCall callPing(GbxCall in_call, XmlRpcServer_Client in_client)
         {
             // process request ...
            //Console.WriteLine("> client #" + in_client.Id + " says: " 
            //     + in_call.Params[0].ToString() + ":"
            //     + in_call.Params[1].ToString());

             // process response ...
             GbxCall response = new GbxCall(new object[] { true });
             response.Handle = in_call.Handle;
             return response;
         }
     }
}

 

客户端直接发送"Ping"和想带的参数就行了,需要多个RPC调用的时候在server上多加RegisterMethod
using System;
using System.Collections.Generic;
using System.Text;
using TMXmlRpcLib;

namespace XMLRPCClient
{
     class Program
     {
         static void Main(string[] args)
         {
             XmlRpcClient Client = new XmlRpcClient("127.0.0.1", 6310);
             if (Client.Connect() != 0)
                 Console.WriteLine("Failed to connect to server."); // xou throw exception.

             // send a test call to our server ...
             GbxCall Result = Client.Request("Test", new object[] { "hello, if you see this message, the example worked!" });

             // if the call was successfull ...
             if (!Result.Error)
             {
                 Console.WriteLine("Ok!");
             }

             // wait for the user to cancel ...
             Console.ReadLine();
         }
     }
}

 

其中用到的TMXmlRpcLib就是C#的XMLRPC的包了。

 

 

转载于:https://www.cnblogs.com/Huayuan/archive/2012/07/18/2598080.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值