コード例 #1
0
        public async Task TcpRpcClientRaisesEventOnDisconnectWhenServerShutdown()
        {
            using (var server = new TcpRpcServerChannel(
                       new BinaryRpcSerializer(),
                       new RpcMessageFactory(),
                       IPAddress.Loopback,
                       11234))
            {
                await server.ListenAsync();

                using (var client = new TcpRpcClientChannel(new BinaryRpcSerializer(),
                                                            new RpcMessageFactory(),
                                                            IPAddress.Loopback,
                                                            11234))
                {
                    await client.ConnectAsync();

                    var wait = new ManualResetEventSlim(false);
                    client.Disconnected += (s, e) =>
                    {
                        Assert.AreSame(client, e.TransportChannel.Channel);
                        wait.Set();
                    };

                    server.Dispose();

                    Assert.IsTrue(wait.Wait(1000));
                }
            }
        }
コード例 #2
0
ファイル: RpcTests.cs プロジェクト: fsdsabel/AdvancedRpc
        private async Task <IRpcServerChannel> CreateServer <T>(T instance, ChannelType channelType, IRpcSerializer serializer = null,
                                                                TokenImpersonationLevel tokenImpersonationLevel = TokenImpersonationLevel.None,
                                                                IRpcObjectRepository localRepository            = null) where T : class
        {
            if (serializer == null)
            {
                serializer = new BinaryRpcSerializer();
            }
            switch (channelType)
            {
            case ChannelType.Tcp:
            {
                var server = new TcpRpcServerChannel(
                    serializer,
                    new RpcMessageFactory(),
                    IPAddress.Loopback,
                    11234,
                    localRepository);
                if (instance != null)
                {
                    server.ObjectRepository.RegisterSingleton(instance);
                }
                await server.ListenAsync();

                return(server);
            }

            case ChannelType.NamedPipe:
            {
                _pipeName = Guid.NewGuid().ToString();
                var server = new NamedPipeRpcServerChannel(
                    serializer,
                    new RpcMessageFactory(),
                    _pipeName,
                    localRepository: localRepository);
                if (instance != null)
                {
                    server.ObjectRepository.RegisterSingleton(instance);
                }
                await server.ListenAsync();

                return(server);
            }

            default:
                throw new NotSupportedException();
            }
        }