Пример #1
0
        public void PingWithExtensionTest()
        {
            using (RpcServer server = RpcServer.CreateRpc(iid, new SearchService.ServerStub(new AuthenticatedSearch()))
                                      .AddProtocol("ncacn_np", @"\pipe\p1"))
            {
                UnitTestRpcInterop.RegisterAllExtensions(server.ExtensionRegistry);
                server.Ping += delegate(RpcPingRequest r)
                {
                    if (r.HasExtension(UnitTestRpcInterop.CustomPingDataIn))
                    {
                        return(RpcPingResponse.CreateBuilder()
                               .SetExtension(UnitTestRpcInterop.CustomPingDataOut,
                                             r.GetExtension(UnitTestRpcInterop.CustomPingDataIn))
                               .Build());
                    }
                    return(RpcPingResponse.DefaultInstance);
                };
                server.StartListening();

                using (
                    RpcClient client =
                        RpcClient.ConnectRpc(iid, "ncacn_np", null, @"\pipe\p1").Authenticate(
                            RpcAuthenticationType.Anonymous))
                {
                    UnitTestRpcInterop.RegisterAllExtensions(client.ExtensionRegistry);

                    RpcPingRequest r = RpcPingRequest.CreateBuilder()
                                       .SetExtension(UnitTestRpcInterop.CustomPingDataIn, "ping-request-data")
                                       .Build();
                    RpcPingResponse response = client.Ping(r);
                    Assert.IsTrue(response.HasExtension(UnitTestRpcInterop.CustomPingDataOut));
                    Assert.AreEqual("ping-request-data", response.GetExtension(UnitTestRpcInterop.CustomPingDataOut));
                }
            }
        }
        protected virtual RpcPingResponse OnPing(RpcPingRequest request)
        {
            Converter <RpcPingRequest, RpcPingResponse> ping = Ping;

            if (ping != null)
            {
                RpcPingResponse.Builder response = RpcPingResponse.CreateBuilder();
                foreach (Converter <RpcPingRequest, RpcPingResponse> del in ping.GetInvocationList())
                {
                    response.MergeFrom(del(request));
                }
                return(response.Build());
            }
            return(RpcPingResponse.DefaultInstance);
        }
Пример #3
0
 public RpcPingResponse Ping(RpcPingRequest request)
 {
     return(CallMethod(".ping", request, RpcPingResponse.CreateBuilder()));
 }