0

のサーバー実装を使用しようとすると問題が発生しますMessagePack RPC。会社のクライアントから提供された Python コードに基づいて、クライアント用とサーバー用の実装を 1 つずつ作成しました。

サーバーの実装は Python によって消費される必要がありますが、私が見る限り、それは問題にはなりません。

サーバーの実装:

public class Program
{

    static void Main(string[] args)
    {
        try
        {
            DefaultServiceTypeLocator def = new DefaultServiceTypeLocator();
            ServiceTypeLocator ser = def;

            def.AddService(new Methods().GetType());
            var services = ser.FindServices();

            var configuration = new RpcServerConfiguration();

            IPAddress ipAddress = GetIp();
            configuration.BindingEndPoint = new IPEndPoint(ipAddress, 8089);
            Console.WriteLine(new IPEndPoint(ipAddress, 8089).ToString());
            using (var server = new RpcServer(configuration))
            {
                server.Start();

                Console.ReadKey();
            }
        }
        catch (Exception ex)
        {

            Console.Write(ex);
            Console.ReadKey();
        }
}
[MessagePackRpcServiceContractAttribute]
public class Methods
{
    [MessagePackRpcMethodAttribute]
    public int hello0()
    {
        Console.WriteLine("hello0");
        return 0;
    }
}

クライアントの実装:

public class Program
{
    static void Main(string[] args)
    {
        try
        {
            var configuration = new RpcClientConfiguration();
            IPAddress ipAddress = GetIp();

            using (dynamic proxy = new DynamicRpcProxy(new IPEndPoint(ipAddress, 8089), configuration))
            {
                dynamic res = proxy.hello0();
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
            Console.ReadKey();
        }
    }

    private static IPAddress GetIp()
    {
        string myHost = System.Net.Dns.GetHostName();
        IPAddress myIP = null;

        for (int i = 0; i <= System.Net.Dns.GetHostEntry(myHost).AddressList.Length - 1; i++)
        {
            if (System.Net.Dns.GetHostEntry(myHost).AddressList[i].IsIPv6LinkLocal == false)
            {
                if (System.Net.Dns.GetHostEntry(myHost).AddressList[i].AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                    myIP = System.Net.Dns.GetHostEntry(myHost).AddressList[i];
            }
        }
        return myIP;
    }

}

クライアントがサーバーに接続できず、そこにメソッドが表示されません。エラーは「操作が存在しません」です。

誰にも手がかりはありますか?

ありがとうございました!!

4

1 に答える 1