コード例 #1
0
        private void Init(Uri serverUri)
        {
            // Create a channel factory capable of producing a channel of type IDuplexSessionChannel
            IChannelFactory <IDuplexSessionChannel> factory = new PollingDuplexHttpBinding().BuildChannelFactory <IDuplexSessionChannel>();

            Open(factory);

            // Address of the polling duplex server and creation of the channel to that endpoint
            EndpointAddress endPoint = new EndpointAddress(serverUri.ToString());

            _channel = factory.CreateChannel(endPoint);
            Open(_channel);

            // Use the thread pool to start only one asynchronous request to Receive messages from the server
            // Only start another asynchronous request when a signal is received that the first thread pool thread has received something
            ThreadPool.RegisterWaitForSingleObject(_waitObject, delegate { Receive(_channel, CompleteReceive); }, null, Timeout.Infinite, false);
            _waitObject.Set();
        }