Example #1
0
        protected bool TryLookupUri(Uri requestUri, string requestMethod, System.ServiceModel.HostNameComparisonMode hostNameComparisonMode, out HttpChannelListener listener)
        {
            UriPrefixTable <HttpChannelListener> table;

            listener = null;
            if (requestMethod == null)
            {
                requestMethod = string.Empty;
            }
            Dictionary <string, UriPrefixTable <HttpChannelListener> > addressTables = this.addressTables;
            HttpChannelListener item = null;

            if (((requestMethod.Length > 0) && addressTables.TryGetValue(requestMethod, out table)) && (table.TryLookupUri(requestUri, hostNameComparisonMode, out item) && (string.Compare(requestUri.AbsolutePath, item.Uri.AbsolutePath, StringComparison.OrdinalIgnoreCase) != 0)))
            {
                item = null;
            }
            if (addressTables.TryGetValue(string.Empty, out table) && table.TryLookupUri(requestUri, hostNameComparisonMode, out listener))
            {
                if ((item != null) && (item.Uri.AbsoluteUri.Length >= listener.Uri.AbsoluteUri.Length))
                {
                    listener = item;
                }
            }
            else
            {
                listener = item;
            }
            return(listener != null);
        }
 internal virtual bool IsCompatible(HttpChannelListener listener)
 {
     return(
         (this.hostNameComparisonMode == listener.HostNameComparisonMode) &&
         (this.realm == listener.Realm)
         );
 }
Example #3
0
        internal SharedHttpTransportManager(Uri listenUri, HttpChannelListener channelListener)
            : base(listenUri, channelListener.HostNameComparisonMode, channelListener.Realm)
        {
            this.onGetContext      = Fx.ThunkCallback(new AsyncCallback(OnGetContext));
            this.onMessageDequeued = new Action(OnMessageDequeued);
            this.unsafeConnectionNtlmAuthentication = channelListener.UnsafeConnectionNtlmAuthentication;
            this.onContextReceived = new AsyncCallback(this.HandleHttpContextReceived);
            this.listenerRWLock    = new ReaderWriterLockSlim();

            this.maxPendingAccepts = channelListener.MaxPendingAccepts;
        }
Example #4
0
        static bool EndHttpContextReceived(IAsyncResult httpContextReceivedResult)
        {
            using (DiagnosticUtility.ShouldUseActivity ? (ActivityHolder)httpContextReceivedResult.AsyncState : null)
            {
                HttpChannelListener channelListener =
                    (DiagnosticUtility.ShouldUseActivity ?
                     ((ActivityHolder)httpContextReceivedResult.AsyncState).context :
                     (HttpRequestContext)httpContextReceivedResult.AsyncState).Listener;

                return(channelListener.EndHttpContextReceived(httpContextReceivedResult));
            }
        }
 internal override bool IsCompatible(HttpChannelListener channelListener)
 {
     if (channelListener.InheritBaseAddressSettings)
     {
         return(true);
     }
     if (!channelListener.IsScopeIdCompatible(base.HostNameComparisonMode, base.ListenUri))
     {
         return(false);
     }
     return((channelListener.UnsafeConnectionNtlmAuthentication == this.unsafeConnectionNtlmAuthentication) && base.IsCompatible(channelListener));
 }
        protected bool TryLookupUri(Uri requestUri, string requestMethod,
                                    HostNameComparisonMode hostNameComparisonMode, bool isWebSocketRequest, out HttpChannelListener listener)
        {
            listener = null;

            if (isWebSocketRequest)
            {
                Fx.Assert(StringComparer.OrdinalIgnoreCase.Compare(requestMethod, "GET") == 0, "The requestMethod must be GET in WebSocket case.");
                requestMethod = WebSocketTransportSettings.WebSocketMethod;
            }

            if (requestMethod == null)
            {
                requestMethod = string.Empty;
            }

            UriPrefixTable <HttpChannelListener> addressTable;
            Dictionary <string, UriPrefixTable <HttpChannelListener> > localAddressTables = addressTables;

            // check for a method match if necessary
            HttpChannelListener methodListener = null;

            if (requestMethod.Length > 0)
            {
                if (localAddressTables.TryGetValue(requestMethod, out addressTable))
                {
                    if (addressTable.TryLookupUri(requestUri, hostNameComparisonMode, out methodListener) &&
                        string.Compare(requestUri.AbsolutePath, methodListener.Uri.AbsolutePath, StringComparison.OrdinalIgnoreCase) != 0)
                    {
                        methodListener = null;
                    }
                }
            }
            // and also check the wildcard bucket
            if (localAddressTables.TryGetValue(string.Empty, out addressTable) &&
                addressTable.TryLookupUri(requestUri, hostNameComparisonMode, out listener))
            {
                if (methodListener != null && methodListener.Uri.AbsoluteUri.Length >= listener.Uri.AbsoluteUri.Length)
                {
                    listener = methodListener;
                }
            }
            else
            {
                listener = methodListener;
            }

            return(listener != null);
        }
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context) where TChannel : class, IChannel
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }
            if (!this.CanBuildChannelListener <TChannel>(context))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("TChannel", System.ServiceModel.SR.GetString("CouldnTCreateChannelForChannelType2", new object[] { context.Binding.Name, typeof(TChannel) }));
            }
            HttpChannelListener listener = new HttpChannelListener(this, context);

            AspNetEnvironment.Current.ApplyHostedContext(listener, context);
            return((IChannelListener <TChannel>)listener);
        }
 public ServerWebSocketTransportDuplexSessionChannel(
     HttpChannelListener channelListener,
     EndpointAddress localAddress,
     Uri localVia,
     ConnectionBufferPool bufferPool,
     HttpRequestContext httpRequestContext,
     HttpPipeline httpPipeline,
     HttpResponseMessage httpResponseMessage,
     string subProtocol)
     : base(channelListener, localAddress, localVia, bufferPool)
 {
     this.httpRequestContext  = httpRequestContext;
     this.httpPipeline        = httpPipeline;
     this.httpResponseMessage = httpResponseMessage;
     this.subProtocol         = subProtocol;
 }
Example #9
0
        public override IChannelListener <TChannel> BuildChannelListener <TChannel>(BindingContext context)
        {
            if (context == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("context");
            }

            if (!this.CanBuildChannelListener <TChannel>(context))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(
#pragma warning suppress 56506 // Microsoft, context.Binding will never be null.
                          "TChannel", SR.GetString(SR.CouldnTCreateChannelForChannelType2, context.Binding.Name, typeof(TChannel)));
            }

            UpdateAuthenticationSchemes(context);

            HttpChannelListener listener = new HttpChannelListener <TChannel>(this, context);

            AspNetEnvironment.Current.ApplyHostedContext(listener, context);
            return((IChannelListener <TChannel>)(object) listener);
        }
Example #10
0
 public ListenerHttpContext(HttpChannelListener listener, HttpListenerContext listenerContext) : base(listener, null)
 {
     this.listenerContext = listenerContext;
 }
Example #11
0
 protected HttpRequestContext(HttpChannelListener listener, Message requestMessage) : base(requestMessage, listener.InternalCloseTimeout, listener.InternalSendTimeout)
 {
     this.listener = listener;
 }
        private void OnGetContextCore(IAsyncResult result)
        {
            bool flag = false;

            while (!flag)
            {
                Exception exception = null;
                try
                {
                    try
                    {
                        HttpListenerContext listenerContext = null;
                        lock (base.ThisLock)
                        {
                            if (this.listener == null)
                            {
                                break;
                            }
                            listenerContext = this.listener.EndGetContext(result);
                        }
                        HttpChannelListener listener = null;
                        using (DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.BoundOperation(base.Activity) : null)
                        {
                            using (ServiceModelActivity activity = DiagnosticUtility.ShouldUseActivity ? ServiceModelActivity.CreateBoundedActivityWithTransferInOnly(listenerContext.Request.RequestTraceIdentifier) : null)
                            {
                                if (activity != null)
                                {
                                    base.StartReceiveBytesActivity(activity, listenerContext.Request.Url);
                                }
                                if (DiagnosticUtility.ShouldTraceInformation)
                                {
                                    TraceUtility.TraceHttpConnectionInformation(listenerContext.Request.LocalEndPoint.ToString(), listenerContext.Request.RemoteEndPoint.ToString(), this);
                                }
                                base.TraceMessageReceived(base.ListenUri);
                                if (base.TryLookupUri(listenerContext.Request.Url, listenerContext.Request.HttpMethod, base.HostNameComparisonMode, out listener))
                                {
                                    flag = listener.HttpContextReceived(HttpRequestContext.CreateContext(listener, listenerContext), this.onMessageDequeued);
                                }
                                else
                                {
                                    if (DiagnosticUtility.ShouldTraceWarning)
                                    {
                                        TraceUtility.TraceEvent(TraceEventType.Warning, 0x4000b, System.ServiceModel.SR.GetString("TraceCodeHttpChannelMessageReceiveFailed"), null);
                                    }
                                    if (string.Compare(listenerContext.Request.HttpMethod, "POST", StringComparison.OrdinalIgnoreCase) != 0)
                                    {
                                        listenerContext.Response.StatusCode = 0x195;
                                        listenerContext.Response.Headers.Add(HttpResponseHeader.Allow, "POST");
                                    }
                                    else
                                    {
                                        listenerContext.Response.StatusCode = 0x194;
                                    }
                                    listenerContext.Response.ContentLength64 = 0L;
                                    listenerContext.Response.Close();
                                }
                            }
                        }
                    }
                    catch (HttpListenerException exception2)
                    {
                        switch (exception2.ErrorCode)
                        {
                        case 8:
                        case 14:
                        case 0x5aa:
                            throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InsufficientMemoryException(System.ServiceModel.SR.GetString("InsufficentMemory"), exception2));
                        }
                        if (!System.ServiceModel.Dispatcher.ExceptionHandler.HandleTransportExceptionHelper(exception2))
                        {
                            throw;
                        }
                    }
                }
                catch (Exception exception3)
                {
                    if (Fx.IsFatal(exception3))
                    {
                        throw;
                    }
                    exception = exception3;
                }
                if (exception != null)
                {
                    base.Fault(exception);
                }
                if (!flag)
                {
                    lock (base.ThisLock)
                    {
                        if (this.listener == null)
                        {
                            continue;
                        }
                        result = this.BeginGetContext(false);
                        if ((result != null) && result.CompletedSynchronously)
                        {
                            continue;
                        }
                        break;
                    }
                }
            }
        }
Example #13
0
 protected HttpRequestContext(HttpChannelListener listener, Message requestMessage, EventTraceActivity eventTraceActivity)
     : base(requestMessage, listener.InternalCloseTimeout, listener.InternalSendTimeout)
 {
     this.listener           = listener;
     this.eventTraceActivity = eventTraceActivity;
 }
Example #14
0
 internal static HttpRequestContext CreateContext(HttpChannelListener listener, HttpListenerContext listenerContext, EventTraceActivity eventTraceActivity)
 {
     return(new ListenerHttpContext(listener, listenerContext, eventTraceActivity));
 }
 internal SharedHttpTransportManager(Uri listenUri, HttpChannelListener channelListener) : base(listenUri, channelListener.HostNameComparisonMode, channelListener.Realm)
 {
     this.onGetContext      = Fx.ThunkCallback(new AsyncCallback(this.OnGetContext));
     this.onMessageDequeued = new Action(this.OnMessageDequeued);
     this.unsafeConnectionNtlmAuthentication = channelListener.UnsafeConnectionNtlmAuthentication;
 }
Example #16
0
 internal static HttpRequestContext CreateContext(HttpChannelListener listener, HttpListenerContext listenerContext)
 {
     return(new ListenerHttpContext(listener, listenerContext));
 }
Example #17
0
 public SharedHttpsTransportManager(Uri listenUri, HttpChannelListener factory) : base(listenUri, factory)
 {
 }
Example #18
0
 public ListenerHttpContext(HttpChannelListener listener,
                            HttpListenerContext listenerContext, EventTraceActivity eventTraceActivity)
     : base(listener, null, eventTraceActivity)
 {
     this.listenerContext = listenerContext;
 }