internal void HttpContextReceived(HostedHttpRequestAsyncResult result)
 {
     using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(base.Activity) : null)
     {
         using (this.CreateReceiveBytesActivity(result))
         {
             HttpChannelListener listener;
             this.TraceConnectionInformation(result);
             if (base.TryLookupUri(result.RequestUri, result.GetHttpMethod(), base.HostNameComparisonMode, out listener))
             {
                 HostedHttpContext context = new HostedHttpContext(listener, result);
                 listener.HttpContextReceived(context, null);
             }
             else
             {
                 if (DiagnosticUtility.ShouldTraceError)
                 {
                     TraceUtility.TraceEvent(TraceEventType.Error, 0x4000b, System.ServiceModel.Activation.SR.TraceCodeHttpChannelMessageReceiveFailed, new StringTraceRecord("IsRecycling", ServiceHostingEnvironment.IsRecycling.ToString(CultureInfo.CurrentCulture)), this, null);
                 }
                 if (ServiceHostingEnvironment.IsRecycling)
                 {
                     throw FxTrace.Exception.AsError(new EndpointNotFoundException(System.ServiceModel.Activation.SR.Hosting_ListenerNotFoundForActivationInRecycling(result.RequestUri.ToString())));
                 }
                 throw FxTrace.Exception.AsError(new EndpointNotFoundException(System.ServiceModel.Activation.SR.Hosting_ListenerNotFoundForActivation(result.RequestUri.ToString())));
             }
         }
     }
 }
        static void OnHttpContextReceived(IAsyncResult httpContextReceivedResult)
        {
            if (httpContextReceivedResult.CompletedSynchronously)
            {
                return;
            }

            Exception completionException = null;

            try
            {
                EndHttpContextReceived(httpContextReceivedResult);
            }
            catch (Exception exception)
            {
                if (Fx.IsFatal(exception))
                {
                    throw;
                }

                completionException = exception;
            }

            if (completionException != null)
            {
                HostedHttpContext context =
                    (HostedHttpContext)(DiagnosticUtility.ShouldUseActivity ?
                                        ((ActivityHolder)httpContextReceivedResult.AsyncState).context :
                                        httpContextReceivedResult.AsyncState);

                context.CompleteWithException(completionException);
            }
        }
 internal void HttpContextReceived(HostedHttpRequestAsyncResult result)
 {
     using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(base.Activity) : null)
     {
         using (this.CreateReceiveBytesActivity(result))
         {
             HttpChannelListener listener;
             this.TraceConnectionInformation(result);
             if (base.TryLookupUri(result.RequestUri, result.GetHttpMethod(), base.HostNameComparisonMode, out listener))
             {
                 HostedHttpContext context = new HostedHttpContext(listener, result);
                 listener.HttpContextReceived(context, null);
             }
             else
             {
                 if (DiagnosticUtility.ShouldTraceError)
                 {
                     TraceUtility.TraceEvent(TraceEventType.Error, 0x4000b, System.ServiceModel.Activation.SR.TraceCodeHttpChannelMessageReceiveFailed, new StringTraceRecord("IsRecycling", ServiceHostingEnvironment.IsRecycling.ToString(CultureInfo.CurrentCulture)), this, null);
                 }
                 if (ServiceHostingEnvironment.IsRecycling)
                 {
                     throw FxTrace.Exception.AsError(new EndpointNotFoundException(System.ServiceModel.Activation.SR.Hosting_ListenerNotFoundForActivationInRecycling(result.RequestUri.ToString())));
                 }
                 throw FxTrace.Exception.AsError(new EndpointNotFoundException(System.ServiceModel.Activation.SR.Hosting_ListenerNotFoundForActivation(result.RequestUri.ToString())));
             }
         }
     }
 }
예제 #4
0
            public HostedHttpInput(HostedHttpContext hostedHttpContext)
                : base(hostedHttpContext.Listener, true, hostedHttpContext.Listener.IsChannelBindingSupportEnabled)
            {
                AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

                this.hostedHttpContext = hostedHttpContext;

                EnvelopeVersion envelopeVersion = hostedHttpContext.Listener.MessageEncoderFactory.Encoder.MessageVersion.Envelope;

                // MB#29602, perf optimization
                if (envelopeVersion == EnvelopeVersion.Soap11)
                {
                    // For soap 1.1, use headers collection to get content-type since we need to pull in the headers
                    // collection for SOAP-Action anyways
                    this.contentType = hostedHttpContext.result.GetContentType();
                }
                else
                {
                    // For soap 1.2, the we pull the action header from the content-type, so don't access the headers
                    // and just use the typed property. For other versions, we shouldn't need the headers up front.
                    this.contentType = hostedHttpContext.result.GetContentTypeFast();
                }

                this.contentLength = hostedHttpContext.result.GetContentLength();

                // MB#34947: System.Web signals chunked as 0 as well so the only way we can
                // differentiate is by reading ahead
                if (this.contentLength == 0)
                {
                    preReadBuffer = hostedHttpContext.result.GetPrereadBuffer(ref this.contentLength);
                }
            }
예제 #5
0
 static void AppendHeaderFromHttpResponseMessageToResponse(HttpResponseMessage response, HostedHttpRequestAsyncResult result)
 {
     HostedHttpContext.AppendHeaderToResponse(response.Headers, result);
     if (response.Content != null)
     {
         HostedHttpContext.AppendHeaderToResponse(response.Content.Headers, result);
     }
 }
예제 #6
0
 protected override void PrepareHttpSendCore(HttpResponseMessage message)
 {
     result.SetStatusCode((int)message.StatusCode);
     if (message.ReasonPhrase != null)
     {
         result.SetStatusDescription(message.ReasonPhrase);
     }
     HostedHttpContext.AppendHeaderFromHttpResponseMessageToResponse(message, this.result);
 }
예제 #7
0
        void BeforeAcceptWebSocket(HttpResponseMessage response)
        {
            this.SetRequestContainer(new HostedRequestContainer(this.result));
            string address = string.Empty;
            int    port    = 0;

            if (this.requestContainer.TryGetAddressAndPort(out address, out port))
            {
                this.remoteEndpointMessageProperty = new RemoteEndpointMessageProperty(address, port);
            }

            this.CloseHostedRequestContainer();

            HostedHttpContext.AppendHeaderFromHttpResponseMessageToResponse(response, this.result);
        }
        internal void HttpContextReceived(HostedHttpRequestAsyncResult result)
        {
            using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(this.Activity) : null)
            {
                using (ServiceModelActivity activity = this.CreateReceiveBytesActivity(result))
                {
                    this.TraceConnectionInformation(result);
                    HttpChannelListener listener;

                    if (base.TryLookupUri(result.RequestUri, result.GetHttpMethod(),
                                          this.HostNameComparisonMode, result.IsWebSocketRequest, out listener))
                    {
                        HostedHttpContext hostedContext             = new HostedHttpContext(listener, result);
                        object            state                     = DiagnosticUtility.ShouldUseActivity ? (object)new ActivityHolder(activity, hostedContext) : (object)hostedContext;
                        IAsyncResult      httpContextReceivedResult = listener.BeginHttpContextReceived(hostedContext,
                                                                                                        null,
                                                                                                        onHttpContextReceived,
                                                                                                        state);
                        if (httpContextReceivedResult.CompletedSynchronously)
                        {
                            EndHttpContextReceived(httpContextReceivedResult);
                        }

                        return;
                    }

                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.HttpChannelMessageReceiveFailed, SR.TraceCodeHttpChannelMessageReceiveFailed,
                                                new StringTraceRecord("IsRecycling", ServiceHostingEnvironment.IsRecycling.ToString(CultureInfo.CurrentCulture)),
                                                this, null);
                    }

                    if (ServiceHostingEnvironment.IsRecycling)
                    {
                        throw FxTrace.Exception.AsError(
                                  new EndpointNotFoundException(SR.Hosting_ListenerNotFoundForActivationInRecycling(result.RequestUri.ToString())));
                    }
                    else
                    {
                        throw FxTrace.Exception.AsError(
                                  new EndpointNotFoundException(SR.Hosting_ListenerNotFoundForActivation(result.RequestUri.ToString())));
                    }
                }
            }
        }
 public HostedHttpInput(HostedHttpContext hostedHttpContext) : base(hostedHttpContext.Listener, true, hostedHttpContext.Listener.IsChannelBindingSupportEnabled)
 {
     this.hostedHttpContext = hostedHttpContext;
     if (hostedHttpContext.Listener.MessageEncoderFactory.Encoder.MessageVersion.Envelope == EnvelopeVersion.Soap11)
     {
         this.contentType = hostedHttpContext.result.GetContentType();
     }
     else
     {
         this.contentType = hostedHttpContext.result.GetContentTypeFast();
     }
     this.contentLength = hostedHttpContext.result.GetContentLength();
     if (this.contentLength == 0)
     {
         this.preReadBuffer = hostedHttpContext.result.GetPrereadBuffer(ref this.contentLength);
     }
 }
 public HostedRequestHttpOutput(HostedHttpRequestAsyncResult result, IHttpTransportFactorySettings settings, Message message, HostedHttpContext context) : base(settings, message, false, false)
 {
     this.result  = result;
     this.context = context;
     if (TransferModeHelper.IsResponseStreamed(settings.TransferMode))
     {
         result.SetTransferModeToStreaming();
     }
     if (message.IsFault)
     {
         this.statusCode = 500;
     }
     else
     {
         this.statusCode = 200;
     }
 }
예제 #11
0
            public HostedRequestHttpOutput(HostedHttpRequestAsyncResult result, IHttpTransportFactorySettings settings,
                                           Message message, HostedHttpContext context)
                : base(settings, message, false, false)
            {
                AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

                this.result  = result;
                this.context = context;

                if (TransferModeHelper.IsResponseStreamed(settings.TransferMode))
                {
                    result.SetTransferModeToStreaming();
                }

                if (message.IsFault)
                {
                    this.statusCode = (int)HttpStatusCode.InternalServerError;
                }
                else
                {
                    this.statusCode = (int)HttpStatusCode.OK;
                }
            }
예제 #12
0
 public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer)
     : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer))
 {
     AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
     this.result = hostedContext.result;
 }
예제 #13
0
 public HostedInputStream(HostedHttpContext hostedContext)
     : base(hostedContext.result.GetInputStream())
 {
     AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
     this.result = hostedContext.result;
 }
예제 #14
0
            public HostedHttpInput(HostedHttpContext hostedHttpContext)
                : base(hostedHttpContext.Listener, true, hostedHttpContext.Listener.IsChannelBindingSupportEnabled)
            {
                AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

                this.hostedHttpContext = hostedHttpContext;

                EnvelopeVersion envelopeVersion = hostedHttpContext.Listener.MessageEncoderFactory.Encoder.MessageVersion.Envelope;

                // MB#29602, perf optimization
                if (envelopeVersion == EnvelopeVersion.Soap11)
                {
                    // For soap 1.1, use headers collection to get content-type since we need to pull in the headers 
                    // collection for SOAP-Action anyways
                    this.contentType = hostedHttpContext.result.GetContentType();
                }
                else
                {
                    // For soap 1.2, the we pull the action header from the content-type, so don't access the headers
                    // and just use the typed property. For other versions, we shouldn't need the headers up front.
                    this.contentType = hostedHttpContext.result.GetContentTypeFast();
                }

                this.contentLength = hostedHttpContext.result.GetContentLength();

                // MB#34947: System.Web signals chunked as 0 as well so the only way we can
                // differentiate is by reading ahead
                if (this.contentLength == 0)
                {
                    preReadBuffer = hostedHttpContext.result.GetPrereadBuffer(ref this.contentLength);
                }
            }
예제 #15
0
 public HostedInputStream(HostedHttpContext hostedContext)
     : base(hostedContext.result.GetInputStream())
 {
     AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
     this.result = hostedContext.result;
 }
 public HostedRequestHttpOutput(HostedHttpRequestAsyncResult result, IHttpTransportFactorySettings settings, Message message, HostedHttpContext context) : base(settings, message, false, false)
 {
     this.result = result;
     this.context = context;
     if (TransferModeHelper.IsResponseStreamed(settings.TransferMode))
     {
         result.SetTransferModeToStreaming();
     }
     if (message.IsFault)
     {
         this.statusCode = 500;
     }
     else
     {
         this.statusCode = 200;
     }
 }
 public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer) : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer))
 {
 }
 public HostedInputStream(HostedHttpContext hostedContext) : base(hostedContext.result.GetInputStream())
 {
 }
 public HostedHttpInput(HostedHttpContext hostedHttpContext) : base(hostedHttpContext.Listener, true, hostedHttpContext.Listener.IsChannelBindingSupportEnabled)
 {
     this.hostedHttpContext = hostedHttpContext;
     if (hostedHttpContext.Listener.MessageEncoderFactory.Encoder.MessageVersion.Envelope == EnvelopeVersion.Soap11)
     {
         this.contentType = hostedHttpContext.result.GetContentType();
     }
     else
     {
         this.contentType = hostedHttpContext.result.GetContentTypeFast();
     }
     this.contentLength = hostedHttpContext.result.GetContentLength();
     if (this.contentLength == 0)
     {
         this.preReadBuffer = hostedHttpContext.result.GetPrereadBuffer(ref this.contentLength);
     }
 }
예제 #20
0
 public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer)
     : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer))
 {
     AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
     this.result = hostedContext.result;
 }
        internal void HttpContextReceived(HostedHttpRequestAsyncResult result)
        {
            using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(this.Activity) : null)
            {
                using (ServiceModelActivity activity = this.CreateReceiveBytesActivity(result))
                {
                    this.TraceConnectionInformation(result);
                    HttpChannelListener listener;

                    if (base.TryLookupUri(result.RequestUri, result.GetHttpMethod(),
                        this.HostNameComparisonMode, result.IsWebSocketRequest, out listener))
                    {
                        HostedHttpContext hostedContext = new HostedHttpContext(listener, result);
                        object state = DiagnosticUtility.ShouldUseActivity ? (object)new ActivityHolder(activity, hostedContext) : (object)hostedContext;
                        IAsyncResult httpContextReceivedResult = listener.BeginHttpContextReceived(hostedContext,
                                                                                                        null,
                                                                                                        onHttpContextReceived,
                                                                                                        state);
                        if (httpContextReceivedResult.CompletedSynchronously)
                        {
                            EndHttpContextReceived(httpContextReceivedResult);
                        }

                        return;
                    }

                    if (DiagnosticUtility.ShouldTraceError)
                    {
                        TraceUtility.TraceEvent(TraceEventType.Error, TraceCode.HttpChannelMessageReceiveFailed, SR.TraceCodeHttpChannelMessageReceiveFailed,
                            new StringTraceRecord("IsRecycling", ServiceHostingEnvironment.IsRecycling.ToString(CultureInfo.CurrentCulture)),
                            this, null);
                    }

                    if (ServiceHostingEnvironment.IsRecycling)
                    {
                        throw FxTrace.Exception.AsError(
                            new EndpointNotFoundException(SR.Hosting_ListenerNotFoundForActivationInRecycling(result.RequestUri.ToString())));
                    }
                    else
                    {
                        throw FxTrace.Exception.AsError(
                            new EndpointNotFoundException(SR.Hosting_ListenerNotFoundForActivation(result.RequestUri.ToString())));
                    }
                }
            }
        }
예제 #22
0
            public HostedRequestHttpOutput(HostedHttpRequestAsyncResult result, IHttpTransportFactorySettings settings,
                Message message, HostedHttpContext context)
                : base(settings, message, false, false)
            {
                AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

                this.result = result;
                this.context = context;

                if (TransferModeHelper.IsResponseStreamed(settings.TransferMode))
                    result.SetTransferModeToStreaming();

                if (message.IsFault)
                {
                    this.statusCode = (int)HttpStatusCode.InternalServerError;
                }
                else
                {
                    this.statusCode = (int)HttpStatusCode.OK;
                }
            }
 public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer) : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer))
 {
 }
 public HostedInputStream(HostedHttpContext hostedContext) : base(hostedContext.result.GetInputStream())
 {
 }
예제 #25
0
 public HostedResponseOutputStream(HostedHttpRequestAsyncResult result, HostedHttpContext context)
     : base(result.GetOutputStream())
 {
     this.context = context;
     this.result = result;
 }
 public HostedResponseOutputStream(HostedHttpRequestAsyncResult result, HostedHttpContext context) : base(result.GetOutputStream())
 {
     this.context = context;
     this.result  = result;
 }