static void OnBeginRequestWithFlow(object state)
        {
            HostedHttpRequestAsyncResult self = (HostedHttpRequestAsyncResult)state;

            IDisposable hostedThreadContext = null;

            try
            {
                if (self.flowContext)
                {
                    // In AspCompat case, these are the three things that need to be flowed.  See HostedHttpInput.
                    if (self.hostedThreadData != null)
                    {
                        hostedThreadContext = self.hostedThreadData.CreateContext();
                    }
                }

                // In full-trust, this simply calls the delegate.
                AspNetPartialTrustHelpers.PartialTrustInvoke(ContextOnBeginRequest, self);
            }
            finally
            {
                if (hostedThreadContext != null)
                {
                    hostedThreadContext.Dispose();
                }
            }
        }
コード例 #2
0
 public static void EndProcessRequest(IAsyncResult ar)
 {
     if (ar is HostedHttpRequestAsyncResult)
     {
         HostedHttpRequestAsyncResult.End(ar);
     }
 }
 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 OnBeginRequest(object state)
        {
            HostedHttpRequestAsyncResult self = (HostedHttpRequestAsyncResult)state;

            Exception completionException = null;

            try
            {
                self.BeginRequest();
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                completionException = e;
            }

            if (completionException != null)
            {
                self.CompleteOperation(completionException);
            }
        }
コード例 #5
0
            public HostedRequestContainer(HostedHttpRequestAsyncResult result)
            {
                AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

                this.result   = result;
                this.thisLock = new object();
            }
 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())));
             }
         }
     }
 }
コード例 #7
0
        public static void ExecuteSynchronous(HttpApplication context, string routeServiceVirtualPath, bool flowContext, bool ensureWFService)
        {
            HostedHttpRequestAsyncResult result;
            AutoResetEvent waitObject = HostedHttpRequestAsyncResult.waitObject;

            if (waitObject == null)
            {
                waitObject = new AutoResetEvent(false);
                HostedHttpRequestAsyncResult.waitObject = waitObject;
            }
            try
            {
                result = new HostedHttpRequestAsyncResult(context, routeServiceVirtualPath, flowContext, ensureWFService, ProcessRequestCompleteCallback, waitObject);
                if (!result.CompletedSynchronously)
                {
                    waitObject.WaitOne();
                }
                waitObject = null;
            }
            finally
            {
                if (waitObject != null)
                {
                    HostedHttpRequestAsyncResult.waitObject = null;
                    waitObject.Close();
                }
            }
            End(result);
        }
コード例 #8
0
        public HostedHttpContext(HttpChannelListener listener, HostedHttpRequestAsyncResult result)
            : base(listener, null, result.EventTraceActivity)
        {
            AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

            this.result = result;
            result.AddRefForImpersonation();
        }
コード例 #9
0
 static public void EndProcessRequest(IAsyncResult ar)
 {
     //No need to call CompletedAsyncResult.End as the asyncResult has already completed.
     if (ar is HostedHttpRequestAsyncResult)
     {
         HostedHttpRequestAsyncResult.End(ar);
     }
 }
コード例 #10
0
        public HostedHttpContext(HttpChannelListener listener, HostedHttpRequestAsyncResult result)
            : base(listener, null, result.EventTraceActivity)
        {
            AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

            this.result = result;
            result.AddRefForImpersonation();
        }
コード例 #11
0
 static void AppendHeaderToResponse(HttpHeaders headers, HostedHttpRequestAsyncResult result)
 {
     foreach (KeyValuePair <string, IEnumerable <string> > header in headers)
     {
         foreach (string value in header.Value)
         {
             result.AppendHeader(header.Key, value);
         }
     }
 }
 internal MetabaseSettingsCassini(HostedHttpRequestAsyncResult result)
 {
     if (!ServiceHostingEnvironment.IsSimpleApplicationHost)
     {
         throw Fx.AssertAndThrowFatal("MetabaseSettingsCassini..ctor() Not a simple application host.");
     }
     string str = string.Format(CultureInfo.InvariantCulture, ":{0}:{1}", new object[] { result.OriginalRequestUri.Port.ToString(NumberFormatInfo.InvariantInfo), "localhost" });
     base.Bindings.Add(result.OriginalRequestUri.Scheme, new string[] { str });
     base.Protocols.Add(result.OriginalRequestUri.Scheme);
 }
コード例 #13
0
        internal MetabaseSettingsCassini(HostedHttpRequestAsyncResult result)
        {
            if (!ServiceHostingEnvironment.IsSimpleApplicationHost)
            {
                throw Fx.AssertAndThrowFatal("MetabaseSettingsCassini..ctor() Not a simple application host.");
            }
            string str = string.Format(CultureInfo.InvariantCulture, ":{0}:{1}", new object[] { result.OriginalRequestUri.Port.ToString(NumberFormatInfo.InvariantInfo), "localhost" });

            base.Bindings.Add(result.OriginalRequestUri.Scheme, new string[] { str });
            base.Protocols.Add(result.OriginalRequestUri.Scheme);
        }
 internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
 {
     if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
     {
         if ((result.ImpersonationContext != null) && result.ImpersonationContext.IsImpersonated)
         {
             this.impersonationContext = result.ImpersonationContext;
             this.impersonationContext.AddRef();
         }
         this.currentThreadData = result.HostedThreadData;
     }
     this.OriginalRequestUri = result.OriginalRequestUri;
 }
コード例 #15
0
        private static void OnBeginRequestWithFlow(object state)
        {
            HostedHttpRequestAsyncResult result = (HostedHttpRequestAsyncResult)state;

            using (IDisposable disposable = null)
            {
                if (result.flowContext && (result.hostedThreadData != null))
                {
                    disposable = result.hostedThreadData.CreateContext();
                }
                AspNetPartialTrustHelpers.PartialTrustInvoke(ContextOnBeginRequest, result);
            }
        }
コード例 #16
0
 internal static void EnsureInitializedForSimpleApplicationHost(HostedHttpRequestAsyncResult result)
 {
     if (singleton == null)
     {
         lock (syncRoot)
         {
             if (singleton == null)
             {
                 singleton = new HostedTransportConfigurationManager(new MetabaseSettingsCassini(result));
             }
         }
     }
 }
コード例 #17
0
 internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
 {
     if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
     {
         if ((result.ImpersonationContext != null) && result.ImpersonationContext.IsImpersonated)
         {
             this.impersonationContext = result.ImpersonationContext;
             this.impersonationContext.AddRef();
         }
         this.currentThreadData = result.HostedThreadData;
     }
     this.OriginalRequestUri = result.OriginalRequestUri;
 }
 public ServiceModelActivity CreateReceiveBytesActivity(HostedHttpRequestAsyncResult result)
 {
     ServiceModelActivity activity = null;
     if (result != null)
     {
         base.TraceMessageReceived(result.RequestUri);
         if (DiagnosticUtility.ShouldUseActivity)
         {
             activity = ServiceModelActivity.CreateBoundedActivity(GetRequestTraceIdentifier(result.Application.Context));
             base.StartReceiveBytesActivity(activity, result.RequestUri);
         }
     }
     return activity;
 }
コード例 #19
0
ファイル: MetabaseSettings.cs プロジェクト: dox0/DotNet471RS3
        internal MetabaseSettingsCassini(HostedHttpRequestAsyncResult result)
            : base()
        {
            if (!ServiceHostingEnvironment.IsSimpleApplicationHost)
            {
                throw Fx.AssertAndThrowFatal("MetabaseSettingsCassini..ctor() Not a simple application host.");
            }

            // The hostName is hard-coded to "localhost" for Cassini.
            string binding = string.Format(CultureInfo.InvariantCulture, ":{0}:{1}", result.OriginalRequestUri.Port.ToString(NumberFormatInfo.InvariantInfo), MetabaseSettings.LocalMachine);

            this.Bindings.Add(result.OriginalRequestUri.Scheme, new string[] { binding });
            this.Protocols.Add(result.OriginalRequestUri.Scheme);
        }
コード例 #20
0
        public ServiceModelActivity CreateReceiveBytesActivity(HostedHttpRequestAsyncResult result)
        {
            ServiceModelActivity activity = null;

            if (result != null)
            {
                base.TraceMessageReceived(result.RequestUri);
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    activity = ServiceModelActivity.CreateBoundedActivity(GetRequestTraceIdentifier(result.Application.Context));
                    base.StartReceiveBytesActivity(activity, result.RequestUri);
                }
            }
            return(activity);
        }
コード例 #21
0
                public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
                {
                    IAsyncResult result;

                    try
                    {
                        result = base.BeginWrite(buffer, offset, count, callback, state);
                    }
                    catch (Exception exception)
                    {
                        this.CheckWrapThrow(exception);
                        throw;
                    }
                    return(result);
                }
コード例 #22
0
        private static void ProcessRequest(object sender, EventArgs e)
        {
            if (!disabled)
            {
                try
                {
                    ServiceHostingEnvironment.SafeEnsureInitialized();
                }
                catch (SecurityException exception)
                {
                    disabled = true;
                    if (DiagnosticUtility.ShouldTraceWarning)
                    {
                        DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                    }
                    return;
                }
                HttpApplication application = (HttpApplication)sender;
                string          currentExecutionFilePathExtension = application.Request.CurrentExecutionFilePathExtension;
                if (!string.IsNullOrEmpty(currentExecutionFilePathExtension))
                {
                    ServiceHostingEnvironment.ServiceType serviceType = ServiceHostingEnvironment.GetServiceType(currentExecutionFilePathExtension);
                    if (serviceType != ServiceHostingEnvironment.ServiceType.Unknown)
                    {
                        if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
                        {
                            if ((serviceType == ServiceHostingEnvironment.ServiceType.Workflow) && ServiceHostingEnvironment.IsConfigurationBasedService(application))
                            {
                                application.Context.RemapHandler(new HttpHandler());
                            }
                        }
                        else
                        {
                            switch (serviceType)
                            {
                            case ServiceHostingEnvironment.ServiceType.WCF:
                                HostedHttpRequestAsyncResult.ExecuteSynchronous(application, false, false);
                                return;

                            case ServiceHostingEnvironment.ServiceType.Workflow:
                                HostedHttpRequestAsyncResult.ExecuteSynchronous(application, false, true);
                                break;
                            }
                        }
                    }
                }
            }
        }
コード例 #23
0
        public ServiceModelActivity CreateReceiveBytesActivity(HostedHttpRequestAsyncResult result)
        {
            ServiceModelActivity retval = null;

            if (result != null)
            {
                TraceMessageReceived(result.EventTraceActivity, result.RequestUri);
                if (DiagnosticUtility.ShouldUseActivity)
                {
                    IServiceProvider provider = (IServiceProvider)result.Application.Context;
                    retval = ServiceModelActivity.CreateBoundedActivity(GetRequestTraceIdentifier(provider));
                    StartReceiveBytesActivity(retval, result.RequestUri);
                }
            }
            return(retval);
        }
コード例 #24
0
        internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
        {
            Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path");

            if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
            {
                if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated)
                {
                    this.impersonationContext = result.ImpersonationContext;
                    this.impersonationContext.AddRef();
                }

                currentThreadData = result.HostedThreadData;
            }

            this.OriginalRequestUri = result.OriginalRequestUri;
        }
コード例 #25
0
        internal HostingMessageProperty(HostedHttpRequestAsyncResult result)
        {
            Fx.Assert(ServiceHostingEnvironment.IsHosted, "should only be called in the hosted path");

            if (ServiceHostingEnvironment.AspNetCompatibilityEnabled)
            {
                if (result.ImpersonationContext != null && result.ImpersonationContext.IsImpersonated)
                {
                    this.impersonationContext = result.ImpersonationContext;
                    this.impersonationContext.AddRef();
                }

                currentThreadData = result.HostedThreadData;
            }

            this.OriginalRequestUri = result.OriginalRequestUri;
        }
コード例 #26
0
 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;
     }
 }
コード例 #27
0
        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())));
                    }
                }
            }
        }
コード例 #28
0
 public void TraceConnectionInformation(HostedHttpRequestAsyncResult result)
 {
     if (((result != null) && DiagnosticUtility.ShouldTraceInformation) && canTraceConnectionInformation)
     {
         try
         {
             HttpWorkerRequest service        = (HttpWorkerRequest)((IServiceProvider)result.Application.Context).GetService(typeof(HttpWorkerRequest));
             string            localEndpoint  = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { service.GetLocalAddress(), service.GetLocalPort() });
             string            remoteEndpoint = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { service.GetRemoteAddress(), service.GetRemotePort() });
             TraceUtility.TraceHttpConnectionInformation(localEndpoint, remoteEndpoint, this);
         }
         catch (SecurityException exception)
         {
             canTraceConnectionInformation = false;
             if (DiagnosticUtility.ShouldTraceWarning)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
             }
         }
     }
 }
コード例 #29
0
        private static void OnBeginRequest(object state)
        {
            HostedHttpRequestAsyncResult result = (HostedHttpRequestAsyncResult)state;
            Exception exception = null;

            try
            {
                result.BeginRequest();
            }
            catch (Exception exception2)
            {
                if (Fx.IsFatal(exception2))
                {
                    throw;
                }
                exception = exception2;
            }
            if (exception != null)
            {
                result.CompleteOperation(exception);
            }
        }
コード例 #30
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;
                }
            }
コード例 #31
0
        public void TraceConnectionInformation(HostedHttpRequestAsyncResult result)
        {
            if (result != null && DiagnosticUtility.ShouldTraceInformation && canTraceConnectionInformation)
            {
                try
                {
                    AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
                    IServiceProvider provider = (IServiceProvider)result.Application.Context;
                    HttpWorkerRequest workerRequest = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
                    string localAddress = string.Format(CultureInfo.InvariantCulture,
                        "{0}:{1}", workerRequest.GetLocalAddress(), workerRequest.GetLocalPort());
                    string remoteAddress = string.Format(CultureInfo.InvariantCulture,
                        "{0}:{1}", workerRequest.GetRemoteAddress(), workerRequest.GetRemotePort());
                    TraceUtility.TraceHttpConnectionInformation(localAddress, remoteAddress, this);
                }
                catch (SecurityException e)
                {
                    canTraceConnectionInformation = false;

                    // not re-throwing on purpose
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                }
            }
        }
コード例 #32
0
        public void TraceConnectionInformation(HostedHttpRequestAsyncResult result)
        {
            if (result != null && DiagnosticUtility.ShouldTraceInformation && canTraceConnectionInformation)
            {
                try
                {
                    AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
                    IServiceProvider  provider      = (IServiceProvider)result.Application.Context;
                    HttpWorkerRequest workerRequest = (HttpWorkerRequest)provider.GetService(typeof(HttpWorkerRequest));
                    string            localAddress  = string.Format(CultureInfo.InvariantCulture,
                                                                    "{0}:{1}", workerRequest.GetLocalAddress(), workerRequest.GetLocalPort());
                    string remoteAddress = string.Format(CultureInfo.InvariantCulture,
                                                         "{0}:{1}", workerRequest.GetRemoteAddress(), workerRequest.GetRemotePort());
                    TraceUtility.TraceHttpConnectionInformation(localAddress, remoteAddress, this);
                }
                catch (SecurityException e)
                {
                    canTraceConnectionInformation = false;

                    // not re-throwing on purpose
                    DiagnosticUtility.TraceHandledException(e, TraceEventType.Warning);
                }
            }
        }
コード例 #33
0
 static HostingMessageProperty CreateMessagePropertyFromHostedResult(HostedHttpRequestAsyncResult result)
 {
     return new HostingMessageProperty(result);
 }
コード例 #34
0
 static void AppendHeaderToResponse(HttpHeaders headers, HostedHttpRequestAsyncResult result)
 {
     foreach (KeyValuePair<string, IEnumerable<string>> header in headers)
     {
         foreach (string value in header.Value)
         {
             result.AppendHeader(header.Key, value);
         }
     }
 }
コード例 #35
0
 static void AppendHeaderFromHttpResponseMessageToResponse(HttpResponseMessage response, HostedHttpRequestAsyncResult result)
 {
     HostedHttpContext.AppendHeaderToResponse(response.Headers, result);
     if (response.Content != null)
     {
         HostedHttpContext.AppendHeaderToResponse(response.Content.Headers, result);
     }
 }
コード例 #36
0
 public HostedResponseOutputStream(HostedHttpRequestAsyncResult result, HostedHttpContext context) : base(result.GetOutputStream())
 {
     this.context = context;
     this.result  = result;
 }
コード例 #37
0
 public ServiceModelActivity CreateReceiveBytesActivity(HostedHttpRequestAsyncResult result)
 {
     ServiceModelActivity retval = null;
     if (result != null)
     {
         TraceMessageReceived(result.EventTraceActivity, result.RequestUri);
         if (DiagnosticUtility.ShouldUseActivity)
         {
             IServiceProvider provider = (IServiceProvider)result.Application.Context;
             retval = ServiceModelActivity.CreateBoundedActivity(GetRequestTraceIdentifier(provider));
             StartReceiveBytesActivity(retval, result.RequestUri);
         }
     }
     return retval;
 }
        internal static void EnsureInitializedForSimpleApplicationHost(HostedHttpRequestAsyncResult result)
        {
            if (singleton != null)
            {
                return;
            }

            lock (syncRoot)
            {
                if (singleton != null)
                    return;

                singleton = new HostedTransportConfigurationManager(new MetabaseSettingsCassini(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;
     }
 }
コード例 #40
0
 public HostedRequestContainer(HostedHttpRequestAsyncResult result)
 {
     this.result   = result;
     this.thisLock = new object();
 }
 public void ProcessRequest(HttpContext context)
 {
     ServiceHostingEnvironment.SafeEnsureInitialized();
     HostedHttpRequestAsyncResult.ExecuteSynchronous(context.ApplicationInstance, this.serviceVirtualPath, true, false);
 }
コード例 #42
0
 public HostedResponseOutputStream(HostedHttpRequestAsyncResult result, HostedHttpContext context)
     : base(result.GetOutputStream())
 {
     this.context = context;
     this.result = result;
 }
コード例 #43
0
        public static void ExecuteSynchronous(HttpApplication context, string routeServiceVirtualPath, bool flowContext, bool ensureWFService)
        {
            AutoResetEvent wait = HostedHttpRequestAsyncResult.waitObject;
            if (wait == null)
            {
                wait = new AutoResetEvent(false);
                HostedHttpRequestAsyncResult.waitObject = wait;
            }

            HostedHttpRequestAsyncResult result;
            try
            {
                result = new HostedHttpRequestAsyncResult(context, routeServiceVirtualPath, flowContext, ensureWFService, ProcessRequestCompleteCallback, wait);
                if (!result.CompletedSynchronously)
                {
                    wait.WaitOne();
                }
                wait = null;
            }
            finally
            {
                if (wait != null)
                {
                    // Not sure of the state anymore.
                    HostedHttpRequestAsyncResult.waitObject = null;
                    wait.Close();
                }
            }

            HostedHttpRequestAsyncResult.End(result);
        }
コード例 #44
0
 public HostedInputStream(HostedHttpContext hostedContext)
     : base(hostedContext.result.GetInputStream())
 {
     AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
     this.result = hostedContext.result;
 }
 public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     IAsyncResult result;
     try
     {
         result = base.BeginWrite(buffer, offset, count, callback, state);
     }
     catch (Exception exception)
     {
         this.CheckWrapThrow(exception);
         throw;
     }
     return result;
 }
コード例 #46
0
 public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer)
     : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer))
 {
     AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();
     this.result = hostedContext.result;
 }
コード例 #47
0
        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())));
                    }
                }
            }
        }
コード例 #48
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 void TraceConnectionInformation(HostedHttpRequestAsyncResult result)
 {
     if (((result != null) && DiagnosticUtility.ShouldTraceInformation) && canTraceConnectionInformation)
     {
         try
         {
             HttpWorkerRequest service = (HttpWorkerRequest) ((IServiceProvider) result.Application.Context).GetService(typeof(HttpWorkerRequest));
             string localEndpoint = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { service.GetLocalAddress(), service.GetLocalPort() });
             string remoteEndpoint = string.Format(CultureInfo.InvariantCulture, "{0}:{1}", new object[] { service.GetRemoteAddress(), service.GetRemotePort() });
             TraceUtility.TraceHttpConnectionInformation(localEndpoint, remoteEndpoint, this);
         }
         catch (SecurityException exception)
         {
             canTraceConnectionInformation = false;
             if (DiagnosticUtility.ShouldTraceWarning)
             {
                 DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
             }
         }
     }
 }
コード例 #50
0
            public HostedRequestContainer(HostedHttpRequestAsyncResult result)
            {
                AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet();

                this.result = result;
                this.thisLock = new object();
            }
 public HostedHttpContext(HttpChannelListener listener, HostedHttpRequestAsyncResult result) : base(listener, null)
 {
     this.result = result;
 }
 public void EndProcessRequest(IAsyncResult result)
 {
     HostedHttpRequestAsyncResult.End(result);
 }
 public HostedRequestContainer(HostedHttpRequestAsyncResult result)
 {
     this.result = result;
     this.thisLock = new object();
 }
コード例 #54
0
        internal MetabaseSettingsCassini(HostedHttpRequestAsyncResult result)
            : base()
        {
            if (!ServiceHostingEnvironment.IsSimpleApplicationHost)
            {
                throw Fx.AssertAndThrowFatal("MetabaseSettingsCassini..ctor() Not a simple application host.");
            }

            // The hostName is hard-coded to "localhost" for Cassini.
            string binding = string.Format(CultureInfo.InvariantCulture, ":{0}:{1}", result.OriginalRequestUri.Port.ToString(NumberFormatInfo.InvariantInfo), MetabaseSettings.LocalMachine);
            this.Bindings.Add(result.OriginalRequestUri.Scheme, new string[] { binding });
            this.Protocols.Add(result.OriginalRequestUri.Scheme);
        }
コード例 #55
0
 public HostedHttpContext(HttpChannelListener listener, HostedHttpRequestAsyncResult result) : base(listener, null)
 {
     this.result = result;
 }