Ejemplo n.º 1
0
        IAsyncResult BeginGetContextCore(EventTraceActivity eventTraceActivity)
        {
            using (LockHelper.TakeReaderLock(this.listenerRWLock))
            {
                if (this.listener == null)
                {
                    return(null);
                }

                return(this.listener.BeginGetContext(onGetContext, eventTraceActivity));
            }
        }
Ejemplo n.º 2
0
        bool EnqueueContext(IAsyncResult listenerContextResult)
        {
            EventTraceActivity  eventTraceActivity = null;
            HttpListenerContext listenerContext;
            bool enqueued = false;

            if (FxTrace.Trace.IsEnd2EndActivityTracingEnabled)
            {
                eventTraceActivity = (EventTraceActivity)listenerContextResult.AsyncState;
                if (eventTraceActivity == null)
                {
                    eventTraceActivity = EventTraceActivity.GetFromThreadOrCreate(true);
                }
            }

            using (LockHelper.TakeReaderLock(this.listenerRWLock))
            {
                if (this.listener == null)
                {
                    return(true);
                }

                listenerContext = this.listener.EndGetContext(listenerContextResult);
            }

            // Grab the activity from the context and set that as the surrounding activity.
            // If a message appears, we will transfer to the message's activity next
            using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(this.Activity) : null)
            {
                ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivityWithTransferInOnly(listenerContext.Request.RequestTraceIdentifier) : null;
                try
                {
                    if (activity != null)
                    {
                        StartReceiveBytesActivity(activity, listenerContext.Request.Url);
                    }
                    if (DiagnosticUtility.ShouldTraceInformation)
                    {
                        TraceUtility.TraceHttpConnectionInformation(listenerContext.Request.LocalEndPoint.ToString(),
                                                                    listenerContext.Request.RemoteEndPoint.ToString(), this);
                    }

                    base.TraceMessageReceived(eventTraceActivity, this.ListenUri);

                    HttpChannelListener channelListener;
                    if (base.TryLookupUri(listenerContext.Request.Url,
                                          listenerContext.Request.HttpMethod,
                                          this.HostNameComparisonMode,
                                          listenerContext.Request.IsWebSocketRequest,
                                          out channelListener))
                    {
                        HttpRequestContext context = HttpRequestContext.CreateContext(channelListener, listenerContext, eventTraceActivity);

                        IAsyncResult httpContextReceivedResult = channelListener.BeginHttpContextReceived(context,
                                                                                                          onMessageDequeued,
                                                                                                          onContextReceived,
                                                                                                          DiagnosticUtility.ShouldUseActivity ? (object)new ActivityHolder(activity, context) : (object)context);
                        if (httpContextReceivedResult.CompletedSynchronously)
                        {
                            enqueued = EndHttpContextReceived(httpContextReceivedResult);
                        }
                        else
                        {
                            // The callback has been enqueued.
                            enqueued = true;
                        }
                    }
                    else
                    {
                        HandleMessageReceiveFailed(listenerContext);
                    }
                }
                finally
                {
                    if (DiagnosticUtility.ShouldUseActivity && activity != null)
                    {
                        if (!enqueued)
                        {
                            // Error during enqueuing
                            activity.Dispose();
                        }
                    }
                }
            }

            return(enqueued);
        }