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(); } } }
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); } }
public HostedRequestContainer(HostedHttpRequestAsyncResult result) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.result = result; this.thisLock = new object(); }
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); }
public HostedHttpContext(HttpChannelListener listener, HostedHttpRequestAsyncResult result) : base(listener, null, result.EventTraceActivity) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.result = result; result.AddRefForImpersonation(); }
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); } }
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); }
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; }
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); } }
internal static void EnsureInitializedForSimpleApplicationHost(HostedHttpRequestAsyncResult result) { if (singleton == null) { lock (syncRoot) { if (singleton == null) { singleton = new HostedTransportConfigurationManager(new MetabaseSettingsCassini(result)); } } } }
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; }
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); }
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); }
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); }
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; } } } } } }
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 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; }
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; } }
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 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); } } } }
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); } }
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 { 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); } } }
static HostingMessageProperty CreateMessagePropertyFromHostedResult(HostedHttpRequestAsyncResult result) { return new HostingMessageProperty(result); }
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); } } }
static void AppendHeaderFromHttpResponseMessageToResponse(HttpResponseMessage response, HostedHttpRequestAsyncResult result) { HostedHttpContext.AppendHeaderToResponse(response.Headers, result); if (response.Content != null) { HostedHttpContext.AppendHeaderToResponse(response.Content.Headers, result); } }
public HostedResponseOutputStream(HostedHttpRequestAsyncResult result, HostedHttpContext context) : base(result.GetOutputStream()) { this.context = context; this.result = result; }
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 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); }
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); }
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; }
public HostedInputStream(HostedHttpContext hostedContext, byte[] preReadBuffer) : base(new PreReadStream(hostedContext.result.GetInputStream(), preReadBuffer)) { AspNetPartialTrustHelpers.FailIfInPartialTrustOutsideAspNet(); this.result = hostedContext.result; }
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); } } } }
public HostedHttpContext(HttpChannelListener listener, HostedHttpRequestAsyncResult result) : base(listener, null) { this.result = result; }
public void EndProcessRequest(IAsyncResult result) { HostedHttpRequestAsyncResult.End(result); }