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)); } } }
public void RoundTripCallContextExtensionsTest() { using (RpcServer server = RpcServer.CreateRpc(iid, new SearchService.ServerStub(new AuthenticatedSearch())) .AddProtocol("ncacn_np", @"\pipe\p1")) { UnitTestRpcInterop.RegisterAllExtensions(server.ExtensionRegistry); server.Ping += delegate { String strValue = RpcCallContext.Current.GetExtension(UnitTestRpcInterop.CustomContextString); UInt64 intValue = RpcCallContext.Current.GetExtension(UnitTestRpcInterop.CustomContextNumber); char[] tmp = strValue.ToCharArray(); Array.Reverse(tmp); strValue = new string(tmp); intValue = ~intValue; RpcCallContext.Current = RpcCallContext.Current.ToBuilder() .SetExtension(UnitTestRpcInterop.CustomContextString, strValue) .SetExtension(UnitTestRpcInterop.CustomContextNumber, intValue) .Build(); return(RpcPingResponse.DefaultInstance); }; server.StartListening(); using ( RpcClient client = RpcClient.ConnectRpc(iid, "ncacn_np", null, @"\pipe\p1").Authenticate( RpcAuthenticationType.Anonymous)) { UnitTestRpcInterop.RegisterAllExtensions(client.ExtensionRegistry); client.CallContext = client.CallContext.ToBuilder() .SetExtension(UnitTestRpcInterop.CustomContextString, "abc") .SetExtension(UnitTestRpcInterop.CustomContextNumber, 0x70000000FFFFFFFFUL) .Build(); client.Ping(); Assert.AreEqual("cba", client.CallContext.GetExtension(UnitTestRpcInterop.CustomContextString)); Assert.AreEqual(~0x70000000FFFFFFFFUL, client.CallContext.GetExtension(UnitTestRpcInterop.CustomContextNumber)); } } }