private static NetworkDetector.ConnectivityStatus CheckTcpConnectivity(Uri baseAddress, out Exception exception) { NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable; exception = null; if (!RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTP", false) && !RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTPS", false)) { try { BinaryMessageEncodingBindingElement binaryMessageEncodingBindingElement = new BinaryMessageEncodingBindingElement(); TcpTransportBindingElement tcpTransportBindingElement = new TcpTransportBindingElement(); tcpTransportBindingElement.ConnectionPoolSettings.MaxOutboundConnectionsPerEndpoint = 100; tcpTransportBindingElement.MaxReceivedMessageSize = (long)65536; CustomBinding customBinding = new CustomBinding(); customBinding.Elements.Add(binaryMessageEncodingBindingElement); customBinding.Elements.Add(tcpTransportBindingElement); customBinding.OpenTimeout = TimeSpan.FromSeconds(10); customBinding.SendTimeout = TimeSpan.FromSeconds(10); customBinding.ReceiveTimeout = TimeSpan.MaxValue; int num = 9350; Uri uri = ServiceBusUriHelper.CreateServiceUri("net.tcp", string.Concat(baseAddress.DnsSafeHost, ":", num.ToString(CultureInfo.InvariantCulture)), "/"); IChannelFactory <IDuplexSessionChannel> channelFactory = null; IDuplexSessionChannel duplexSessionChannel = null; try { channelFactory = customBinding.BuildChannelFactory <IDuplexSessionChannel>(new object[0]); channelFactory.Open(); duplexSessionChannel = channelFactory.CreateChannel(new EndpointAddress(uri, new AddressHeader[0])); duplexSessionChannel.Open(); Message message = Message.CreateMessage(MessageVersion.Default, "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/OnewayPing", new OnewayPingMessage()); duplexSessionChannel.Send(message, customBinding.SendTimeout); duplexSessionChannel.Close(); duplexSessionChannel = null; channelFactory.Close(); channelFactory = null; } finally { if (duplexSessionChannel != null) { duplexSessionChannel.Abort(); } if (channelFactory != null) { channelFactory.Abort(); } } connectivityStatu = NetworkDetector.ConnectivityStatus.Available; } catch (CommunicationException communicationException) { exception = communicationException; } catch (TimeoutException timeoutException) { exception = timeoutException; } } NetworkDetector.LogResult(baseAddress, "Tcp", connectivityStatu); return(connectivityStatu); }
private void AddTokenToMessage(Message message, TimeSpan timeout) { HttpRequestMessageProperty item; if (this.tokenProvider == null) { return; } this.ValidateTransportProtectionForToken(); string str = "Send"; if (message.Properties.ContainsKey(HttpRequestMessageProperty.Name)) { item = message.Properties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; } else { item = new HttpRequestMessageProperty(); message.Properties.Add(HttpRequestMessageProperty.Name, item); } if (!this.tokenProvider.IsWebTokenSupported) { throw new NotSupportedException(SRClient.HTTPAuthTokenNotSupportedException); } string str1 = ServiceBusUriHelper.NormalizeUri(message.Headers.To ?? this.via, false); string webToken = this.tokenProvider.GetWebToken(str1, str, false, timeout); item.Headers["ServiceBusAuthorization"] = webToken; }
internal static string RemoveServicePathPrefix(string path) { string str; ServiceBusUriHelper.TryRemoveServicePathPrefix(path, out str, true); return(str); }
private static bool ValidateServiceNamespace(string serviceNamespace) { if (string.IsNullOrEmpty(serviceNamespace)) { return(false); } return(ServiceBusUriHelper.IsBasicLatinNonControlString(serviceNamespace)); }
private string NormalizeAppliesTo(Uri namespaceAddress, string appliesTo) { if (namespaceAddress == null) { return(this.NormalizeAppliesTo(appliesTo)); } string str = (this.TokenScope != Microsoft.ServiceBus.TokenScope.Namespace || !(namespaceAddress != null) ? appliesTo : namespaceAddress.AbsoluteUri); return(ServiceBusUriHelper.NormalizeUri(str, "http", this.StripQueryParameters, false, true)); }
private static NetworkDetector.ConnectivityStatus CheckHttpsWebStreamConnectivity(Uri baseAddress, out Exception exception) { NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable; exception = null; if (WebStream.IsSupportingScheme(ServiceBusUriHelper.CreateServiceUri("https", baseAddress.Authority, "/"), out exception)) { connectivityStatu = NetworkDetector.ConnectivityStatus.Available; } NetworkDetector.LogResult(baseAddress, "https WebStream", connectivityStatu); return(connectivityStatu); }
internal static Uri CreateServiceUri(string scheme, string authority, string servicePath, bool suppressRelayPathPrefix) { UriBuilder uriBuilder = new UriBuilder(string.Concat("tempscheme://", authority)); if (uriBuilder.Port == -1) { uriBuilder.Port = ServiceBusUriHelper.GetSchemePort(scheme); } uriBuilder.Scheme = scheme; uriBuilder.Path = ServiceBusUriHelper.RefinePath(servicePath, suppressRelayPathPrefix); return(uriBuilder.Uri); }
protected override IEnumerator <IteratorAsyncResult <WebSocketRelayedConnectionListener.ConnectAsyncResult> .AsyncStep> GetAsyncSteps() { Uri uri = ServiceBusUriHelper.CreateServiceUri(Uri.UriSchemeHttps, this.Request.HttpsEndpoint.ToString(), "/"); ServiceBusClientWebSocket serviceBusClientWebSocket = new ServiceBusClientWebSocket("wsrelayedconnection"); yield return(base.CallAsync((WebSocketRelayedConnectionListener.ConnectAsyncResult thisPtr, TimeSpan t, AsyncCallback c, object s) => serviceBusClientWebSocket.BeginConnect(uri.Host, uri.Port, ConnectConstants.ConnectionInitiateTimeout, c, s), (WebSocketRelayedConnectionListener.ConnectAsyncResult thisPtr, IAsyncResult r) => serviceBusClientWebSocket.EndConnect(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.connection = new ClientWebSocketConnection(serviceBusClientWebSocket, this.relayedConnectionListener.bufferSize, this.relayedConnectionListener.uri, this.Activity); this.message = Message.CreateMessage(this.relayedConnectionListener.messageHelper.MessageVersion, "RelayedAccept", new AcceptMessage(this.Request.Id)); this.message.Headers.To = EndpointAddress.AnonymousUri; WebSocketRelayedConnectionListener.ConnectAsyncResult connectAsyncResult = this; IteratorAsyncResult <WebSocketRelayedConnectionListener.ConnectAsyncResult> .BeginCall beginCall = (WebSocketRelayedConnectionListener.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.relayedConnectionListener.messageHelper.BeginSendMessage(thisRef.connection, thisRef.message, t, c, s); yield return(connectAsyncResult.CallAsync(beginCall, (WebSocketRelayedConnectionListener.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.relayedConnectionListener.messageHelper.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.relayedConnectionListener.BeginConnectCallback), this.connection); }
internal static Uri CreateServiceUri(string scheme, string serviceNamespace, string hostName, string servicePath, bool suppressRelayPathPrefix) { string str; if (string.IsNullOrEmpty(serviceNamespace)) { str = hostName; } else { CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] objArray = new object[] { serviceNamespace, hostName }; str = string.Format(invariantCulture, "{0}.{1}", objArray); } return(ServiceBusUriHelper.CreateServiceUri(scheme, str, servicePath, suppressRelayPathPrefix)); }
private static Uri CreateServiceUri(string scheme, string serviceNamespace, string servicePath, bool suppressRelayPathPrefix, string hostName) { string str = serviceNamespace.Trim(); ServiceBusEnvironment.ValidateSchemeAndNamespace(scheme, str); if (!servicePath.EndsWith("/", StringComparison.Ordinal)) { servicePath = string.Concat(servicePath, "/"); } Uri uri = ServiceBusUriHelper.CreateServiceUri(scheme, str, hostName, servicePath, suppressRelayPathPrefix); if (!ServiceBusUriHelper.IsSafeBasicLatinUriPath(uri)) { throw new ArgumentException(SRClient.PathSegmentASCIICharacters, servicePath); } return(uri); }
protected override IEnumerator <IteratorAsyncResult <WebStreamRelayedConnectionListener.ConnectAsyncResult> .AsyncStep> GetAsyncSteps() { Uri uri; uri = (!this.relayedConnectionListener.useHttpsMode ? ServiceBusUriHelper.CreateServiceUri(Uri.UriSchemeHttp, this.Request.HttpEndpoint.ToString(), "/") : ServiceBusUriHelper.CreateServiceUri(Uri.UriSchemeHttps, this.Request.HttpsEndpoint.ToString(), "/")); WebStream webStream = (new WebStream(uri, "connection", this.relayedConnectionListener.useHttpsMode, this.Activity, this.relayedConnectionListener.uri)).Open(); this.connection = new WebStreamConnection(uri, this.relayedConnectionListener.bufferSize, this.Activity, webStream, this.relayedConnectionListener.uri); WebStreamRelayedConnectionListener.ConnectAsyncResult connectAsyncResult = this; IteratorAsyncResult <WebStreamRelayedConnectionListener.ConnectAsyncResult> .BeginCall beginCall = (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => SecureSocketUtil.BeginInitiateSecureClientUpgradeIfNeeded(thisRef.connection, null, thisRef.relayedConnectionListener.socketSecurityMode, thisRef.relayedConnectionListener.uri.Host, t, c, s); yield return(connectAsyncResult.CallAsync(beginCall, (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.connection = SecureSocketUtil.EndInitiateSecureClientUpgradeIfNeeded(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); this.message = Message.CreateMessage(this.relayedConnectionListener.messageHelper.MessageVersion, "RelayedAccept", new AcceptMessage(this.Request.Id)); this.message.Headers.To = EndpointAddress.AnonymousUri; WebStreamRelayedConnectionListener.ConnectAsyncResult connectAsyncResult1 = this; IteratorAsyncResult <WebStreamRelayedConnectionListener.ConnectAsyncResult> .BeginCall beginCall1 = (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, TimeSpan t, AsyncCallback c, object s) => thisRef.relayedConnectionListener.messageHelper.BeginSendMessage(thisRef.connection, thisRef.message, t, c, s); yield return(connectAsyncResult1.CallAsync(beginCall1, (WebStreamRelayedConnectionListener.ConnectAsyncResult thisRef, IAsyncResult r) => thisRef.relayedConnectionListener.messageHelper.EndSendMessage(r), IteratorAsyncResult <TIteratorAsyncResult> .ExceptionPolicy.Transfer)); IOThreadScheduler.ScheduleCallbackNoFlow(new Action <object>(this.relayedConnectionListener.BeginConnectCallback), this.connection); }
private static NetworkDetector.ConnectivityStatus CheckHttpConnectivity(Uri baseAddress, out Exception exception) { NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable; exception = null; try { Uri uri = ServiceBusUriHelper.CreateServiceUri("http", baseAddress.Authority, "/"); WebRequest webRequest = WebRequest.Create(uri); webRequest.Method = "GET"; StreamReader streamReader = new StreamReader(webRequest.GetResponse().GetResponseStream()); using (streamReader) { streamReader.ReadToEnd(); } connectivityStatu = NetworkDetector.ConnectivityStatus.Available; } catch (WebException webException) { exception = webException; } NetworkDetector.LogResult(baseAddress, "Http", connectivityStatu); return(connectivityStatu); }
private static NetworkDetector.ConnectivityStatus CheckHttpWebStreamConnectivity(Uri baseAddress, out Exception exception) { NetworkDetector.ConnectivityStatus connectivityStatu = NetworkDetector.ConnectivityStatus.Unavailable; exception = null; if (!RelayEnvironment.GetEnvironmentVariable("RELAYFORCEHTTPS", false) && WebStream.IsSupportingScheme(ServiceBusUriHelper.CreateServiceUri("http", baseAddress.Authority, "/"), out exception)) { connectivityStatu = NetworkDetector.ConnectivityStatus.Available; } NetworkDetector.LogResult(baseAddress, "Http WebStream", connectivityStatu); return(connectivityStatu); }
protected virtual string NormalizeAppliesTo(string appliesTo) { return(ServiceBusUriHelper.NormalizeUri(appliesTo, "http", this.StripQueryParameters, this.TokenScope == Microsoft.ServiceBus.TokenScope.Namespace, true)); }
internal static Uri CreateServiceUri(string scheme, string serviceNamespace, string hostName, string servicePath) { return(ServiceBusUriHelper.CreateServiceUri(scheme, serviceNamespace, hostName, servicePath, false)); }
internal static Uri CreateServiceUri(string scheme, string authority, string servicePath) { return(ServiceBusUriHelper.CreateServiceUri(scheme, authority, servicePath, false)); }
internal static bool TryRemoveServicePathPrefix(string path, out string refinedPath) { return(ServiceBusUriHelper.TryRemoveServicePathPrefix(path, out refinedPath, false)); }
protected override string NormalizeAppliesTo(string appliesTo) { return(ServiceBusUriHelper.NormalizeUri(appliesTo, "http", this.StripQueryParameters, false, false)); }
internal static string NormalizeUri(Uri uri, bool ensureTrailingSlash = false) { return(ServiceBusUriHelper.NormalizeUri(uri.AbsoluteUri, uri.Scheme, true, false, ensureTrailingSlash)); }