예제 #1
0
        public static bool IsSupportingScheme(Uri factoryEndpointUri, out Exception exception)
        {
            bool flag;

            exception = null;
            try
            {
                using (WebStream webStream = new WebStream(factoryEndpointUri, "connection", new EventTraceActivity()))
                {
                    flag = webStream.Connect();
                }
            }
            catch (WebException webException1)
            {
                WebException webException = webException1;
                string       str          = WebStream.CloseResponseInWebException(webException);
                exception = new CommunicationException(string.Concat(webException.Message, str), webException);
                flag      = false;
            }
            catch (Exception exception2)
            {
                Exception exception1 = exception2;
                if (Fx.IsFatal(exception1))
                {
                    throw;
                }
                exception = exception1;
                flag      = false;
            }
            return(flag);
        }
예제 #2
0
        public WebStream Open()
        {
            int       num;
            Exception communicationException = null;
            int       num1 = 5;

            do
            {
                int num2 = num1 - 1;
                try
                {
                    MessagingClientEtwProvider.Provider.WebStreamConnecting(base.Activity, this.factoryEndpointUri.AbsoluteUri, this.sbUri.AbsoluteUri, num2);
                    if (this.Connect())
                    {
                        MessagingClientEtwProvider.Provider.WebStreamConnectCompleted(base.Activity, this.factoryEndpointUri.AbsoluteUri, this.sbUri.AbsoluteUri, num2);
                        return(this);
                    }
                }
                catch (WebException webException1)
                {
                    WebException webException = webException1;
                    if (Fx.IsFatal(webException))
                    {
                        throw;
                    }
                    string str = WebStream.CloseResponseInWebException(webException);
                    communicationException = new CommunicationException(string.Concat(webException.Message, str), webException);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    communicationException = exception;
                }
                string str1 = (communicationException != null ? communicationException.ToString() : "Failed to connect. No exception thrown.");
                MessagingClientEtwProvider.Provider.WebStreamConnectFailed(base.Activity, this.factoryEndpointUri.AbsoluteUri, this.sbUri.AbsoluteUri, num2, str1);
                this.Reset();
                this.disposed = false;
                num           = num1 - 1;
                num1          = num;
            }while (num > 0);
            this.disposed = true;
            throw Fx.Exception.AsError(new CommunicationException(SRClient.HTTPConnectivityMode, communicationException), null);
        }
예제 #3
0
        private PumpStream CreateUpStreamRequest(Uri endpointLocation)
        {
            PumpStream pumpStream;

            try
            {
                this.PreauthorizeUpStreamRequestIfNeeded(endpointLocation, this.proxyAuthMode);
                this.upstreamRequest        = (HttpWebRequest)WebRequest.Create(endpointLocation);
                this.upstreamRequest.Method = "POST";
                this.upstreamRequest.ConnectionGroupName          = this.connectionGroupId;
                this.upstreamRequest.SendChunked                  = true;
                this.upstreamRequest.Timeout                      = this.timeoutForUpDownRequestInMiliSecond;
                this.upstreamRequest.ServicePoint.ConnectionLimit = 2048;
                if (endpointLocation.Scheme == Uri.UriSchemeHttps && this.upstreamRequest.ServicePoint.ProtocolVersion != HttpVersion.Version11)
                {
                    try
                    {
                        typeof(ServicePoint).GetProperty("HttpBehaviour", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(this.upstreamRequest.ServicePoint, (byte)0, null);
                    }
                    catch (Exception exception1)
                    {
                        Exception exception = exception1;
                        if (!Fx.IsFatal(exception))
                        {
                            this.upstreamRequest = null;
                            throw Fx.Exception.AsError(new CommunicationException(SRClient.UpstreamConnection, exception), null);
                        }
                        throw;
                    }
                }
                this.upstreamRequest.ServicePoint.UseNagleAlgorithm = false;
                this.upstreamRequest.ServicePoint.Expect100Continue = false;
                this.upstreamRequest.ContentType = "application/octet-stream";
                this.upstreamRequest.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                this.upstreamRequest.AllowWriteStreamBuffering = false;
                this.upstreamRequest.Headers.Add("X-WSCONNECT", this.webStreamRole);
                this.upstreamRequest.Headers.Add("X-PROCESS-AT", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/roles/relay");
                if (this.upstreamRequest.Proxy != null)
                {
                    this.ConfigureProxy(this.upstreamRequest, this.proxyAuthMode);
                }
                this.ConfigurePreauthorizationRequest(this.upstreamRequest, this.proxyAuthMode);
                this.upstreamRequest.ServicePoint.UseNagleAlgorithm = false;
                this.upstreamRequest.ServicePoint.Expect100Continue = false;
                this.upstreamRequest.ServicePoint.ConnectionLimit   = 2048;
                this.sessionServicePoint = this.upstreamRequest.ServicePoint;
                Stream requestStream = this.upstreamRequest.GetRequestStream();
                ThrottledPipeStream throttledPipeStream  = new ThrottledPipeStream(25, WebStream.NaglingDelay);
                ThrottledPipeStream throttledPipeStream1 = throttledPipeStream;
                Stream            stream            = requestStream;
                FramingOutputPump framingOutputPump = new FramingOutputPump(new BufferRead(throttledPipeStream1.Read), new BufferWrite(stream.Write), 5000, base.Activity, this.factoryEndpointUri);
                PumpStream        writePumpStream   = new WritePumpStream(throttledPipeStream, requestStream, framingOutputPump)
                {
                    PumpCompletedEvent = new Action(this.OnWriteStreamCompleted)
                };
                writePumpStream.BeginRunPump();
                pumpStream = writePumpStream;
            }
            catch (Exception exception3)
            {
                Exception exception2 = exception3;
                if (!Fx.IsFatal(exception2))
                {
                    string str = WebStream.CloseResponseInWebException(exception2);
                    throw Fx.Exception.AsError(new CommunicationException(string.Concat(SRClient.UpstreamConnection, str), exception2), null);
                }
                throw;
            }
            return(pumpStream);
        }
예제 #4
0
        private void CreateSession(out Uri endpointLocation1, out Uri endpointLocation2)
        {
            WebStream.ProxyAuthMode[] proxyAuthModeArray = new WebStream.ProxyAuthMode[] { WebStream.ProxyAuthMode.None, WebStream.ProxyAuthMode.Kerberos, WebStream.ProxyAuthMode.Ntlm, WebStream.ProxyAuthMode.Other };
            this.proxyAuthMode = WebStream.ProxyAuthMode.None;
            string empty = string.Empty;

            WebStream.ProxyAuthMode[] proxyAuthModeArray1 = proxyAuthModeArray;
            int num = 0;

Label1:
            while (num < (int)proxyAuthModeArray1.Length)
            {
                WebStream.ProxyAuthMode proxyAuthMode = proxyAuthModeArray1[num];
                switch (proxyAuthMode)
                {
                case WebStream.ProxyAuthMode.Kerberos:
                {
                    if (empty.Contains("KERBEROS"))
                    {
                        break;
                    }
                    goto Label0;
                }

                case WebStream.ProxyAuthMode.Ntlm:
                {
                    if (!empty.Contains("NTLM"))
                    {
                        goto Label0;
                    }
                    else
                    {
                        break;
                    }
                }
                }
                try
                {
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.factoryEndpointUri);
                    httpWebRequest.KeepAlive   = false;
                    httpWebRequest.Method      = "POST";
                    httpWebRequest.ContentType = "text/plain";
                    httpWebRequest.Headers.Add("X-WSCREATE", this.webStreamRole);
                    httpWebRequest.Headers.Add("X-PROCESS-AT", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/roles/relay");
                    if (httpWebRequest.Proxy != null)
                    {
                        this.ConfigureProxy(httpWebRequest, proxyAuthMode);
                    }
                    httpWebRequest.ServicePoint.ConnectionLimit = 2048;
                    using (Stream requestStream = httpWebRequest.GetRequestStream())
                    {
                        using (StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.UTF8))
                        {
                            streamWriter.Write(string.Empty);
                            streamWriter.Flush();
                        }
                    }
                    HttpWebResponse response = (HttpWebResponse)httpWebRequest.GetResponse();
                    if (response.StatusCode != HttpStatusCode.Created || response.Headers["X-WSENDPT1"] == null || response.Headers["X-WSENDPT2"] == null)
                    {
                        throw Fx.Exception.AsWarning(new CommunicationException(SRClient.FaultyEndpointResponse), null);
                    }
                    if (!Uri.TryCreate(response.Headers["X-WSENDPT1"], UriKind.Absolute, out endpointLocation1))
                    {
                        throw Fx.Exception.AsWarning(new CommunicationException(SRClient.URIEndpoint), null);
                    }
                    if (!Uri.TryCreate(response.Headers["X-WSENDPT2"], UriKind.Absolute, out endpointLocation2))
                    {
                        throw Fx.Exception.AsWarning(new CommunicationException(SRClient.URIEndpoint), null);
                    }
                    response.Close();
                    this.proxyAuthMode = proxyAuthMode;
                }
                catch (WebException webException1)
                {
                    WebException    webException    = webException1;
                    HttpWebResponse httpWebResponse = webException.Response as HttpWebResponse;
                    if (httpWebResponse == null || httpWebResponse.StatusCode != HttpStatusCode.ProxyAuthenticationRequired)
                    {
                        string str = WebStream.CloseResponseInWebException(webException);
                        throw Fx.Exception.AsWarning(new CommunicationException(string.Concat(SRClient.FactoryEndpoint, str), webException), null);
                    }
                    empty = httpWebResponse.Headers["Proxy-Authenticate"].ToUpperInvariant();
                    goto Label0;
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    if (!Fx.IsFatal(exception))
                    {
                        throw Fx.Exception.AsError(new CommunicationException(SRClient.FactoryEndpoint, exception), null);
                    }
                    throw;
                }
                return;
            }
            ExceptionTrace exceptionTrace   = Fx.Exception;
            CultureInfo    invariantCulture = CultureInfo.InvariantCulture;

            object[] objArray = new object[] { empty };
            throw exceptionTrace.AsError(new CommunicationException(string.Format(invariantCulture, "Failed to authenticate with proxy supporting modes '{0}'.", objArray)), null);
Label0:
            num++;
            goto Label1;
        }