RemoteEndpointMessageProperty.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 / WCF / ServiceModel / System / ServiceModel / Channels / RemoteEndpointMessageProperty.cs / 1 / RemoteEndpointMessageProperty.cs

                            //---------------------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{ 
    using System;
    using System.Net; 
    using System.Collections.Specialized; 
    using System.ServiceModel.Activation;
 
    public sealed class RemoteEndpointMessageProperty
    {
        string address;
        int port; 
        IPEndPoint remoteEndPoint;
        HostedRequestContainer hostedRequestContainer; 
        InitializationState state; 
        object thisLock = new object();
 
        public RemoteEndpointMessageProperty(string address, int port)
        {
            if (string.IsNullOrEmpty(address))
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("address");
            } 
 
            if (port < IPEndPoint.MinPort || port > IPEndPoint.MaxPort)
            { 
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("port",
                    SR.GetString(SR.ValueMustBeInRange, IPEndPoint.MinPort, IPEndPoint.MaxPort));
            }
 
            this.port = port;
            this.address = address; 
            this.state = InitializationState.All; 
        }
 
        internal RemoteEndpointMessageProperty(HostedRequestContainer hostedRequestContainer)
        {
            this.hostedRequestContainer = hostedRequestContainer;
        } 

        internal RemoteEndpointMessageProperty(IPEndPoint remoteEndPoint) 
        { 
            this.remoteEndPoint = remoteEndPoint;
        } 

        public static string Name
        {
            get { return "System.ServiceModel.Channels.RemoteEndpointMessageProperty"; } 
        }
 
        public string Address 
        {
            get 
            {
                if ((this.state & InitializationState.Address) != InitializationState.Address)
                {
                    lock (ThisLock) 
                    {
                        if ((this.state & InitializationState.Address) != InitializationState.Address) 
                        { 
                            Initialize(false);
                        } 
                    }
                }
                return this.address;
            } 
        }
 
        public int Port 
        {
            get 
            {
                if ((this.state & InitializationState.Port) != InitializationState.Port)
                {
                    lock (ThisLock) 
                    {
                        if ((this.state & InitializationState.Port) != InitializationState.Port) 
                        { 
                            Initialize(true);
                        } 
                    }
                }
                return this.port;
            } 
        }
 
        object ThisLock 
        {
            get { return thisLock; } 
        }

        void Initialize(bool getHostedPort)
        { 
            if (remoteEndPoint != null)
            { 
                this.address = remoteEndPoint.Address.ToString(); 
                this.port = remoteEndPoint.Port;
                this.state = InitializationState.All; 
                this.remoteEndPoint = null;
            }
            else
            { 
                if ((this.state & InitializationState.Address) != InitializationState.Address)
                { 
                    this.address = hostedRequestContainer.GetRemoteAddress(); 
                    this.state |= InitializationState.Address;
                } 

                if (getHostedPort)
                {
                    this.port = hostedRequestContainer.GetRemotePort(); 
                    this.state |= InitializationState.Port;
                    this.hostedRequestContainer = null; 
                } 
            }
        } 

        [Flags]
        enum InitializationState
        { 
            None = 0,
            Address = 1, 
            Port = 2, 
            All = 3
        } 
    }
}

// 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