예제 #1
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 });
        }
예제 #2
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);
        }
예제 #3
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();
        }