public IConnection Connect(Uri uri, TimeSpan timeout)
        {
            WebSocketConnectAsyncResult webSocketConnectAsyncResult = (new WebSocketConnectAsyncResult(uri, timeout, this.webSocketRole, null, null)).RunSynchronously();
            IConnection clientWebSocketConnection = new ClientWebSocketConnection(webSocketConnectAsyncResult.ClientWebSocket, this.bufferSize, uri, new EventTraceActivity());

            MessagingClientEtwProvider.Provider.WebSocketConnectionEstablished(clientWebSocketConnection.Activity, webSocketConnectAsyncResult.Uri.AbsoluteUri);
            return(clientWebSocketConnection);
        }
        public Microsoft.ServiceBus.Channels.IConnection Connect(Uri uri, TimeSpan timeout)
        {
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);
            WebSocketConnectAsyncResult webSocketConnectAsyncResult = (new WebSocketConnectAsyncResult(uri, timeout, "wsrelayedconnection", null, null)).RunSynchronously();
            ClientWebSocketConnection   clientWebSocketConnection   = new ClientWebSocketConnection(webSocketConnectAsyncResult.ClientWebSocket, this.bufferSize, uri, new EventTraceActivity());

            MessagingClientEtwProvider.Provider.WebSocketConnectionEstablished(clientWebSocketConnection.Activity, uri.AbsoluteUri);
            this.SendRelayedConnectAndReceiveResponse(clientWebSocketConnection, timeoutHelper);
            return(clientWebSocketConnection);
        }
        public Microsoft.ServiceBus.Channels.IConnection EndConnect(IAsyncResult result)
        {
            WebSocketConnectAsyncResult webSocketConnectAsyncResult = AsyncResult <WebSocketConnectAsyncResult> .End(result);

            TimeoutHelper             timeoutHelper             = new TimeoutHelper(webSocketConnectAsyncResult.TimeRemaining());
            ClientWebSocketConnection clientWebSocketConnection = null;

            if (result.IsCompleted)
            {
                clientWebSocketConnection = new ClientWebSocketConnection(webSocketConnectAsyncResult.ClientWebSocket, this.bufferSize, webSocketConnectAsyncResult.Uri, new EventTraceActivity());
                MessagingClientEtwProvider.Provider.WebSocketConnectionEstablished(clientWebSocketConnection.Activity, webSocketConnectAsyncResult.Uri.AbsoluteUri);
                this.SendRelayedConnectAndReceiveResponse(clientWebSocketConnection, timeoutHelper);
            }
            return(clientWebSocketConnection);
        }