ContentOnlyMessage.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 / ContentOnlyMessage.cs / 1 / ContentOnlyMessage.cs

                            //---------------------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------------------
namespace System.ServiceModel.Channels
{ 
    using System;
    using System.ServiceModel; 
    using System.IO; 
    using System.ServiceModel.Diagnostics;
    using System.Xml; 

    /// 
    /// Base class for non-SOAP messages
    ///  
    abstract class ContentOnlyMessage : Message
    { 
        MessageHeaders headers; 
        MessageProperties properties;
 
        protected ContentOnlyMessage()
        {
            this.headers = new MessageHeaders(MessageVersion.None);
        } 

        public override MessageHeaders Headers 
        { 
            get
            { 
                if (IsDisposed)
                {
#pragma warning suppress 56503 // [....], required by base class contract
                    throw TraceUtility.ThrowHelperError(CreateMessageDisposedException(), this); 
                }
 
                return this.headers; 
            }
        } 

        public override MessageProperties Properties
        {
            get 
            {
                if (IsDisposed) 
                { 
#pragma warning suppress 56503 // [....], required by base class contract
                    throw TraceUtility.ThrowHelperError(CreateMessageDisposedException(), this); 
                }

                if (this.properties == null)
                { 
                    this.properties = new MessageProperties();
                } 
 
                return this.properties;
            } 
        }

        public override MessageVersion Version
        { 
            get
            { 
                return headers.MessageVersion; 
            }
        } 

        protected override void OnBodyToString(XmlDictionaryWriter writer)
        {
            OnWriteBodyContents(writer); 
        }
    } 
 
    class StringMessage : ContentOnlyMessage
    { 
        string data;

        public StringMessage(string data)
            : base() 
        {
            this.data = data; 
        } 

        public override bool IsEmpty 
        {
            get
            {
                return String.IsNullOrEmpty(this.data); 
            }
        } 
 
        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        { 
            if (data != null && data.Length > 0)
            {
                writer.WriteElementString("BODY", data);
            } 
        }
    } 
 
    class NullMessage : StringMessage
    { 
        public NullMessage()
            : base(string.Empty)
        {
        } 
    }
} 

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