예제 #1
0
        static void AddCustomer(RpcClientApi client, RpcProto.Customer customer)
        {
            var request = new RpcProto.Request()
              {
            method = RpcProto.RequestType.PostCustomer,
            post = new RpcProto.PostCustomerRequest()
            {
              customer = customer
            }
              };

              var stream = new MemoryStream();
              ProtoBuf.Serializer.Serialize(stream, request);

              var task = ExecuteAsync(client, stream).ContinueWith(r =>
              {
            var response = ProtoBuf.Serializer.Deserialize<RpcProto.PostCustomerResponse>(
              new MemoryStream(r.Result.response));

            if (0 != response.result)
            {
              throw new Exception(response.ToString());
            }
              });

              task.Wait();
        }
예제 #2
0
        static Task<RpcClientApi.ExecuteAsyncResponse> ExecuteAsync(RpcClientApi client, Stream stream)
        {
            byte[] buf = new byte[stream.Length];
              stream.Seek(0, SeekOrigin.Begin);
              stream.Read(buf, 0, buf.Length);

              return client.ExecuteAsync(buf);
        }
예제 #3
0
        public Form1()
        {
            InitializeComponent();

              var iid = new Guid("{04f5e707-d969-4822-95c5-2f3d4fd47f77}");
              client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "3242");
              client.AuthenticateAs(RpcClientApi.Self);
              subscribeEvent();
        }
예제 #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            RpcLibrary.Log.VerboseEnabled = true;
              var iid = new Guid("{78323803-786f-4f7b-908d-b2e89c41d45f}");
              var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "11111");
              client.AuthenticateAs(RpcClientApi.Self);

              byte[] response = client.Execute(new byte[] { 1 });
        }
예제 #5
0
        static byte[] Execute(RpcClientApi client, Stream stream)
        {
            byte[] buffer = new byte[stream.Length];

              stream.Seek(0, SeekOrigin.Begin);
              stream.Read(buffer, 0, buffer.Length);

              return client.Execute(buffer);
        }
예제 #6
0
        static void Main(string[] args)
        {
            RpcLibrary.Log.VerboseEnabled = true;
              // The client and server must agree on the interface id to use:
              var iid = new Guid("{f4db45dc-0dcb-4003-b680-56c40f6cb6a8}");

              bool attempt = true;
              while (attempt)
              {
            attempt = false;
            // Open the connection based on the endpoint information and interface IID
            using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "1234"))
            //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
            {
              // Provide authentication information (not nessessary for LRPC)
              client.AuthenticateAs(RpcClientApi.Self);

              // Send the request and get a response
              try
              {
            var response = client.Execute(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetings" : args[0]));
            Console.WriteLine("Server response: {0}", Encoding.UTF8.GetString(response));

            var task = client.ExecuteAsync(Encoding.UTF8.GetBytes(args.Length == 0 ? "Greetines" : args[0])).
              ContinueWith<String>( r =>
              {
                return Encoding.UTF8.GetString(r.Result.response);
              });

            task.Wait();

            Console.WriteLine("Server response by async way: {0}", task.Result);

              }
              catch (RpcException rx)
              {
            if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
            {
              //Use a wait handle if your on the same box...
              Console.Error.WriteLine("Waiting for server...");
              System.Threading.Thread.Sleep(1000);
              attempt = true;
            }
            else
              Console.Error.WriteLine(rx);
              }
              catch (Exception ex)
              {
            Console.Error.WriteLine(ex);
              }
            }
              }
              // done...
              Console.WriteLine("Press [Enter] to exit...");
              Console.ReadLine();
        }
예제 #7
0
        static List<RpcProto.Customer> GetCustomers(RpcClientApi client)
        {
            var request = new RpcProto.Request()
              {
            method =  RpcProto.RequestType.GetCustomers,
            get = new RpcProto.GetCustomerRequest()
              };
              var stream = new MemoryStream();

              ProtoBuf.Serializer.Serialize(stream, request);
              var output = Execute(client, stream);

              var response = ProtoBuf.Serializer.Deserialize<RpcProto.GetCustomerResponse>(new MemoryStream(output));
              if (0 != response.result)
              {
            throw new Exception(response.ToString());
              }

              return response.customers;
        }
예제 #8
0
        void onEvent(RpcClientApi.ExecuteAsyncResponse response)
        {
            bSubscribed = false;

              textBox1.AppendText(String.Format("{0} Event received. result={1}, response={2}\r\n",
            DateTime.UtcNow, response.result, response.response));

              if (response.result != RpcError.RPC_S_SERVER_UNAVAILABLE)
              {
            subscribeEvent();
              }
        }
예제 #9
0
        static void Main(string[] args)
        {
            RpcLibrary.Log.VerboseEnabled = true;
              // The client and server must agree on the interface id to use:
              var iid = new Guid("{0092F74D-0EA7-4667-A89F-A04C64244031}");

              bool attempt = true;
              while (attempt)
              {
            attempt = false;
            // Open the connection based on the endpoint information and interface IID
            using (var client = new RpcClientApi(iid, RpcProtseq.ncalrpc, null, "5678"))
            {
              //using (var client = new RpcClientApi(iid, RpcProtseq.ncacn_ip_tcp, null, @"18081"))
              client.AuthenticateAs(RpcClientApi.Self);

              // Send the request and get a response
              try
              {
            GetCustomers(client);

            AddCustomer(client, new RpcProto.Customer() { firstName = "Jack", lastName = "Dancer" });

            RemoveCustomer(client, new RpcProto.Customer() { firstName = "Marry", lastName = "Player" });
              }
              catch (RpcException rx)
              {
            if (rx.RpcError == RpcError.RPC_S_SERVER_UNAVAILABLE || rx.RpcError == RpcError.RPC_S_SERVER_TOO_BUSY)
            {
              //Use a wait handle if your on the same box...
              Console.Error.WriteLine("Waiting for server...");
              System.Threading.Thread.Sleep(1000);
              attempt = true;
            }
            else
              Console.Error.WriteLine(rx);
              }
              catch (Exception ex)
              {
            Console.Error.WriteLine(ex);
              }
            }
              }

              // done...
              Console.WriteLine("Press [Enter] to exit...");
              Console.ReadLine();
        }