• 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的包了。

     

     

  • 相关阅读:
    Vue.js
    docker搭建pxc
    mkvirtualenv管理python版本
    gitlab
    centos7安装kvm及kvm管理
    centos7安装docker
    【从NIO到Netty】8.零拷贝案例2-网络传输
    【从NIO到Netty】7.零拷贝案例1-复制文件
    【从NIO到Netty】6.零拷贝介绍
    【从NIO到Netty】5.NIO EchoServer
  • 原文地址:https://www.cnblogs.com/Huayuan/p/2598080.html
Copyright © 2020-2023  润新知