Esempio n. 1
0
 public void Connect()
 {
     using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
     using (new ClientService(host.LocalEndPoint))
     {
     }
 }
Esempio n. 2
0
        protected void Application_Start(object sender, EventArgs e)
        {
            _host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0), new ProtoHostConfiguration
            {
                MinimumProtocolNumber = 1,
                MaximumProtocolNumber = 1
            });

            WebConfigurationManager.AppSettings["protochannel.host"] = _host.LocalEndPoint.ToString();
        }
Esempio n. 3
0
        public void RequestStream()
        {
            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint))
            {
                var response = client.StreamRequest(new StreamRequest());

                var stream = client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null));

                using (var reader = new StreamReader(stream.Stream))
                {
                    Console.WriteLine(reader.ReadToEnd());
                }
            }
        }
Esempio n. 4
0
        public void CloseGracefully()
        {
            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                using (new ClientService(host.LocalEndPoint))
                {
                    var stopwatch = new Stopwatch();

                    stopwatch.Start();
                    host.Close(CloseMode.Gracefully, TimeSpan.FromMilliseconds(100));
                    stopwatch.Stop();

                    Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 90);
                }
            }
        }
        public void ExpectMemoryStream()
        {
            var configuration = new ProtoClientConfiguration
            {
                StreamManager = new HybridStreamManager(Path.GetTempPath(), 50)
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                var response = client.StreamRequest(new StreamRequest { Length = 10 });

                using (var stream = client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null)))
                {
                    Assert.That(stream.Stream, Is.InstanceOf<MemoryStream>());
                }
            }
        }
Esempio n. 6
0
        public void SecureConnect()
        {
            var hostConfig = new ProtoHostConfiguration
            {
                Secure = true,
                Certificate = GetCertificate()
            };

            var clientConfig = new ProtoClientConfiguration
            {
                Secure = true
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0), hostConfig))
            using (new ClientService(host.LocalEndPoint, clientConfig))
            {
            }
        }
        public void StreamTooLong()
        {
            var configuration = new ProtoClientConfiguration
            {
                StreamManager = new HybridStreamManager(Path.GetTempPath(), 50, 100)
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                // TODO: Communicating that the stream was rejected isn't yet
                // communicated clearly.

                var response = client.StreamRequest(new StreamRequest { Length = 200 });

                using (client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null)))
                {
                }
            }
        }
Esempio n. 8
0
        public void CloseWithAbort()
        {
            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                using (new ClientService(host.LocalEndPoint))
                {
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();

                    host.Close(CloseMode.Abort);

                    stopwatch.Stop();

                    // Asserted time is not exact, but it will probably be less
                    // than this.

                    Assert.Less(stopwatch.ElapsedMilliseconds, 100);
                }
            }
        }
        public void RequestStream(StreamDisposition disposition)
        {
            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint))
            {
                var response = client.StreamRequest(new StreamRequest
                {
                    Attachment = disposition == StreamDisposition.Attachment
                });

                using (var protoStream = client.EndGetStream(client.BeginGetStream((int)response.StreamId, null, null)))
                {
                    Assert.AreEqual(protoStream.Disposition, disposition);

                    using (var stream = protoStream.DetachStream())
                    using (var reader = new StreamReader(stream))
                    {
                        Console.WriteLine(reader.ReadToEnd());
                    }
                }
            }
        }
Esempio n. 10
0
        public MainForm()
        {
            InitializeComponent();

            _protoServer = new ProtoHost<ProtoService.ServerService>(new IPEndPoint(IPAddress.Any, Constants.ProtoChannelPort));

            #if _NET_4
            var waitEvent = new ManualResetEvent(false);

            ThreadPool.QueueUserWorkItem(p =>
            {
                _wcfServer = new ServiceHost(typeof(Wcf.ServerService));

                _wcfServer.Open();

                waitEvent.Set();
            });

            waitEvent.WaitOne();
            #else
            _modeWcf.Enabled = false;
            #endif
        }
Esempio n. 11
0
        public void LargeSendStream()
        {
            var callback = new ClientCallbackService();

            var configuration = new ProtoClientConfiguration
            {
                CallbackObject = callback
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                int streamId = client.SendStream(
                    new MemoryStream(new byte[1 << 20]),
                    "Payload.txt",
                    "text/plain"
                );

                client.StreamUpload(new StreamResponse { StreamId = (uint)streamId });

                Assert.True(callback.CallbackReceivedEvent.WaitOne(TimeSpan.FromSeconds(1)));
            }
        }
Esempio n. 12
0
        public void GracefullCloseWithoutFullTimeout()
        {
            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            {
                var stopwatch = new Stopwatch();

                var client = new ClientService(host.LocalEndPoint);

                ThreadPool.QueueUserWorkItem(p =>
                {
                    using (client)
                    {
                        Thread.Sleep(100);
                    }
                });

                stopwatch.Start();
                host.Close(CloseMode.Gracefully, TimeSpan.FromMilliseconds(500));
                stopwatch.Stop();

                Assert.GreaterOrEqual(stopwatch.ElapsedMilliseconds, 90);
                Assert.LessOrEqual(stopwatch.ElapsedMilliseconds, 150);
            }
        }
Esempio n. 13
0
        private void SendWithStreamFailure(long length, StreamFailureType type, bool expectFailure)
        {
            var callback = new ClientCallbackService();

            var configuration = new ProtoClientConfiguration
            {
                CallbackObject = callback
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                int streamId = client.SendStream(
                    new FailingStream(length, type),
                    "Payload.txt",
                    "text/plain"
                );

                client.StreamUpload(new StreamResponse { StreamId = (uint)streamId });

                Assert.True(callback.CallbackReceivedEvent.WaitOne(TimeSpan.FromSeconds(1)));

                if (expectFailure)
                    Assert.AreEqual("Receive stream failed", callback.OneWayPingPayload);
                else
                    Assert.AreNotEqual("Receive stream failed", callback.OneWayPingPayload);
            }
        }
Esempio n. 14
0
        private void SendStream(StreamDisposition disposition)
        {
            var callback = new ClientCallbackService();

            var configuration = new ProtoClientConfiguration
            {
                CallbackObject = callback
            };

            using (var host = new ProtoHost<ServerService>(new IPEndPoint(IPAddress.Loopback, 0)))
            using (var client = new ClientService(host.LocalEndPoint, configuration))
            {
                int streamId = client.SendStream(
                    new MemoryStream(Encoding.UTF8.GetBytes("Payload")),
                    "Payload.txt",
                    "text/plain",
                    disposition
                );

                client.StreamUpload(new StreamResponse { StreamId = (uint)streamId });

                Assert.True(callback.CallbackReceivedEvent.WaitOne(TimeSpan.FromSeconds(1)));
                Assert.True(callback.OneWayPingPayload.Contains(disposition.ToString()));
            }
        }