zoukankan      html  css  js  c++  java
  • 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的包了。

     

     

  • 相关阅读:
    Flume-NG源码分析-整体结构及配置载入分析
    Flume之核心架构深入解析
    使用maven构建scala项目
    大数据的一些面试题
    HBase原理和设计
    Hive UDAF开发详解
    Hive UDTF开发指南
    Hive UDF开发指南
    局域网访问电脑中VMware虚拟机
    百度面试-前端
  • 原文地址:https://www.cnblogs.com/Huayuan/p/2598080.html
Copyright © 2011-2022 走看看