public void Connect() { Disconnect(); _log.DebugFormat("Connecting '{0}'", _endpointAddress); if (_messagingFactory == null) { _messagingFactory = _endpointAddress.MessagingFactoryFactory(); } // check if it's a queue or a subscription to subscribe either the queue or the subscription? if (_endpointAddress.QueueDescription != null) { _messageSender = _endpointAddress.CreateQueue() .ContinueWith(t => { t.Wait(); return(_messagingFactory.TryCreateMessageSender(_endpointAddress.QueueDescription, _prefetchCount).Result); }) .Result; } else { _messageSender = _messagingFactory.TryCreateMessageSender(_endpointAddress.TopicDescription) .Result; } if (_messageSender == null) { throw new TransportException(_endpointAddress.Uri, "The create message sender on messaging factory returned null."); } }