BodyWriter 클래스

정의

메시지 본문 작성기를 나타냅니다.

public ref class BodyWriter abstract
public abstract class BodyWriter
type BodyWriter = class
Public MustInherit Class BodyWriter
상속
BodyWriter
파생

예제

다음 예제에서는 BodyWriter에서 클래스를 파생하는 방법을 보여 줍니다. 이 재지정은 문자열 배열을 가져와서 XmlDictionaryWriter에 씁니다.

using System;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Xml;

namespace UEBodyWriter
{
    class MyBodyWriter : BodyWriter
    {
        const string textTag = "text";
        string[] bodySegment;

        public MyBodyWriter(string[] strData) : base(true)
        {
            int length = strData.Length;

            this.bodySegment = new string[length];
            for (int i = 0; i < length; i++)
            {
                this.bodySegment[i] = strData[i];
            }
        }

        protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
        {
           writer.WriteStartElement(textTag);

           foreach (string str in bodySegment)
           {
               writer.WriteString(str);
           }

            writer.WriteEndElement();
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            string[] strings = {"Hello", "world"};
            MyBodyWriter bw = new MyBodyWriter(strings);

            StringBuilder strBuilder = new StringBuilder(10);
            XmlWriter writer = XmlWriter.Create(strBuilder);
            XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);

            bw.WriteBodyContents(dictionaryWriter);
            dictionaryWriter.Flush();
        }
    }
}


Imports System.Text
Imports System.ServiceModel
Imports System.ServiceModel.Channels
Imports System.Xml

Namespace UEBodyWriter
    Friend Class MyBodyWriter
        Inherits BodyWriter
        Private Const textTag As String = "text"
        Private bodySegment() As String

        Public Sub New(ByVal strData() As String)
            MyBase.New(True)
            Dim length = strData.Length

            Me.bodySegment = New String(length - 1){}
            For i = 0 To length - 1
                Me.bodySegment(i) = strData(i)
            Next i
        End Sub

        Protected Overrides Sub OnWriteBodyContents(ByVal writer As XmlDictionaryWriter)
           writer.WriteStartElement(textTag)

            For Each str As String In bodySegment
                writer.WriteString(str)
            Next str

            writer.WriteEndElement()
        End Sub
    End Class

    Module Module1
        Sub Main(ByVal args() As String)
            Dim strings() As String = {"Hello", "world"}
            Dim bw As New MyBodyWriter(strings)

            Dim strBuilder As New StringBuilder(10)
            Dim writer = XmlWriter.Create(strBuilder)
            Dim dictionaryWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer)

            bw.WriteBodyContents(dictionaryWriter)
            dictionaryWriter.Flush()
        End Sub
    End Module
End Namespace

설명

메시지는 헤더와 본문으로 구성됩니다. 헤더는 버퍼링되고 본문은 스트리밍됩니다. 본문이 스트리밍되기 때문에 사용자는 본문의 실제 콘텐츠를 메시지에 전달할 수 없습니다. 대신 본문을 쓰기 위해 요청될 때 본문을 쓰기 방법을 아는 클래스를 전달해야 합니다. 이렇게 하려면 BodyWriter에서 파생된 클래스를 Message에 전달합니다. 메시지는 BodyWriter를 사용하여 본문을 써야 할 때마다 XmlWriter에서 파생된 클래스를 호출합니다.

생성자

BodyWriter(Boolean)

버퍼링할지 여부를 명시적으로 나타내는 BodyWriter 클래스의 새 인스턴스를 초기화합니다.

속성

IsBuffered

Write 메서드를 여러 번 호출할 수 있는지 여부를 나타내는 값을 가져옵니다.

메서드

BeginWriteBodyContents(XmlDictionaryWriter, AsyncCallback, Object)

지정된 작성기, 콜백 및 상태를 사용하여 본문 작성기에 대한 본문 내용을 쓰기 시작합니다.

CreateBufferedCopy(Int32)

본문의 버퍼링된 복사본을 만듭니다.

EndWriteBodyContents(IAsyncResult)

본문 내용의 쓰기를 종료합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
OnBeginWriteBodyContents(XmlDictionaryWriter, AsyncCallback, Object)

본문 작성기에서 본문 작성기, 콜백 및 상태를 사용하여 본문 콘텐츠를 작성하기 시작할 경우 이벤트를 발생시킵니다.

OnCreateBufferedCopy(Int32)

본문 콘텐츠를 쓸 때 확장성 지점을 제공합니다.

OnEndWriteBodyContents(IAsyncResult)

본문 작성기가 본문 콘텐츠 작성을 종료할 때 이벤트를 발생시킵니다.

OnWriteBodyContents(XmlDictionaryWriter)

구현 시 본문 콘텐츠를 쓸 때 확장성 지점을 제공합니다.

OnWriteBodyContentsAsync(XmlDictionaryWriter)

메시지 본문 작성기를 나타냅니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)
WriteBodyContents(XmlDictionaryWriter)

메시지 본문 콘텐츠를 씁니다.

적용 대상