Esempio n. 1
0
        private PumpStream CreateDownStreamRequest(Uri endpointLocation)
        {
            PumpStream pumpStream;

            try
            {
                this.downstreamRequest        = (HttpWebRequest)WebRequest.Create(endpointLocation);
                this.downstreamRequest.Method = "GET";
                this.downstreamRequest.ConnectionGroupName = this.connectionGroupId;
                this.downstreamRequest.SendChunked         = false;
                this.downstreamRequest.Timeout             = this.timeoutForUpDownRequestInMiliSecond;
                this.downstreamRequest.CachePolicy         = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
                this.downstreamRequest.Headers.Add("X-WSCONNECT", this.webStreamRole);
                this.downstreamRequest.Headers.Add("X-PROCESS-AT", "http://schemas.microsoft.com/netservices/2009/05/servicebus/connect/roles/relay");
                if (this.downstreamRequest.Proxy != null)
                {
                    this.ConfigureProxy(this.downstreamRequest, this.proxyAuthMode);
                }
                this.downstreamRequest.ServicePoint.UseNagleAlgorithm = false;
                this.downstreamRequest.ServicePoint.Expect100Continue = false;
                this.downstreamRequest.ServicePoint.ConnectionLimit   = 2048;
                Stream responseStream = ((HttpWebResponse)this.downstreamRequest.GetResponse()).GetResponseStream();
                ThrottledPipeStream throttledPipeStream = new ThrottledPipeStream(25, WebStream.NaglingDelay);
                Stream stream = responseStream;
                ThrottledPipeStream throttledPipeStream1 = throttledPipeStream;
                FramingInputPump    framingInputPump     = new FramingInputPump(new BufferRead(stream.Read), new BufferWrite(throttledPipeStream1.Write), new Action(throttledPipeStream.WriteEndOfStream), base.Activity, this.factoryEndpointUri);
                ReadPumpStream      readPumpStream       = new ReadPumpStream(responseStream, throttledPipeStream, framingInputPump)
                {
                    PumpCompletedEvent = new Action(this.OnReadStreamCompleted)
                };
                readPumpStream.BeginRunPump();
                pumpStream = readPumpStream;
            }
            catch (Exception exception1)
            {
                Exception exception = exception1;
                if (!Fx.IsFatal(exception))
                {
                    throw Fx.Exception.AsError(new CommunicationException(SRClient.DownstreamConnection, exception), null);
                }
                throw;
            }
            return(pumpStream);
        }
Esempio n. 2
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);
        }