IncomingWebRequestContext.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / ServiceModel / Web / IncomingWebRequestContext.cs / 1 / IncomingWebRequestContext.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------
#pragma warning disable 1634, 1691
 
namespace System.ServiceModel.Web
{ 
    using System; 
    using System.Globalization;
    using System.Diagnostics.CodeAnalysis; 
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Description;
    using System.ServiceModel.Dispatcher; 
    using System.Net;
    using System.Collections.ObjectModel; 
    using System.Collections.Specialized; 

    public class IncomingWebRequestContext 
    {

        internal const string UriTemplateMatchResultsPropertyName = "UriTemplateMatchResults";
        OperationContext operationContext; 
        internal IncomingWebRequestContext(OperationContext operationContext)
        { 
            Fx.Assert(operationContext != null, "operationContext is null"); 
            this.operationContext = operationContext;
        } 

        public string Accept
        { get { return EnsureMessageProperty().Headers[HttpRequestHeader.Accept]; } }
 
        public long ContentLength
        { get { return long.Parse(this.EnsureMessageProperty().Headers[HttpRequestHeader.ContentLength], CultureInfo.InvariantCulture); } } 
 
        public string ContentType
        { get { return this.EnsureMessageProperty().Headers[HttpRequestHeader.ContentType]; } } 

        public WebHeaderCollection Headers
        { get { return this.EnsureMessageProperty().Headers; } }
 
        public string Method
        { get { return this.EnsureMessageProperty().Method; } } 
        public UriTemplateMatch UriTemplateMatch 
        {
            get 
            {
                if (this.operationContext.IncomingMessageProperties.ContainsKey(UriTemplateMatchResultsPropertyName))
                {
                    return this.operationContext.IncomingMessageProperties[UriTemplateMatchResultsPropertyName] as UriTemplateMatch; 
                }
                else 
                { 
                    return null;
                } 
            }
            set
            {
                this.operationContext.IncomingMessageProperties[UriTemplateMatchResultsPropertyName] = value; 
            }
        } 
 
        public string UserAgent
        { get { return this.EnsureMessageProperty().Headers[HttpRequestHeader.UserAgent]; } } 

        HttpRequestMessageProperty MessageProperty
        { get
            { 
                if (operationContext.IncomingMessageProperties == null)
                { 
                    return null; 
                }
                if (!operationContext.IncomingMessageProperties.ContainsKey(HttpRequestMessageProperty.Name)) 
                {
                    return null;
                }
                return operationContext.IncomingMessageProperties[HttpRequestMessageProperty.Name] as HttpRequestMessageProperty; 
            }
        } 
 
        HttpRequestMessageProperty EnsureMessageProperty()
        { 
            if (this.MessageProperty == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(
                    SR2.GetString(SR2.HttpContextNoIncomingMessageProperty, typeof(HttpRequestMessageProperty).Name))); 
            }
            return this.MessageProperty; 
        } 
    }
} 

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK