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

     

     

  • 相关阅读:
    Codeforces 1111D(退背包、排列组合)
    Codeforces 1152D(dp)
    UVaLive6443(线段树)
    UVaLive6435(dp)
    POJ1741(点分治)
    Codeforces 161D(树形dp)
    BZOJ2595(状压dp)
    关于spring java.lang.IllegalArgumentException: Name for argument type [java.lang.String] 的错误
    FingerPrint Fuzzy Vault Matlab实践
    Mybatis的ResultMap的使用
  • 原文地址:https://www.cnblogs.com/Huayuan/p/2598080.html
Copyright © 2011-2022 走看看