Paulo Morgado

.NET Development & Architecture

Test Content

<p>Test</p>

This Blog

Syndication

Search

Sponsored By

Tags

Visitor Locations

<p><a href="http://www4.clustrmaps.com/counter/maps.php?url=http://PauloMorgado.NET/Blogs/EN" title="Visitor Locations"><img src="http://www4.clustrmaps.com/counter/index2.php?url=http://PauloMorgado.NET/Blogs/EN" alt="Visitor Locations" /></a></p>

News

Unit Test Today! Get Typemock Isolator!

Visitor Locations

Community

Email Notifications

Archives

Optimizing writing for the CustomTextMessageEncoder

As I told before I've been using WFC to call legacy POX web services. Some of them only accept iso-8859-1, others can accept utf-8, but all use MessageVersion.None and the text/xml media type.

But since the new XmlDictionaryWriter is optimized for utf-8, utf-16 and Unicode character encodings and will perform better that the XmlTextWriter I would like to be able to use it when possible. To achieve this, two methods of the CustomTextMessageEncoder need to be changed in order to use the best writer.

public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)

{

    MemoryStream stream = new MemoryStream();

    WriteMessage(message, stream);

    //XmlWriter writer = XmlWriter.Create(stream, this.m_writerSettings);

    //message.WriteMessage(writer);

    //writer.Close();

 

    byte[] messageBytes = stream.GetBuffer();

    int messageLength = (int)stream.Position;

    stream.Close();

 

    int totalLength = messageLength + messageOffset;

    byte[] totalBytes = bufferManager.TakeBuffer(totalLength);

    Array.Copy(messageBytes, 0, totalBytes, messageOffset, messageLength);

 

    ArraySegment<byte> byteArray = new ArraySegment<byte>(totalBytes, messageOffset, messageLength);

    return byteArray;

}

 

public override void WriteMessage(Message message, Stream stream)

{

    if ((this.m_writerSettings.Encoding.WebName == ValidatingUTF8.WebName) || (this.m_writerSettings.Encoding.WebName == ValidatingUTF16.WebName) || (this.m_writerSettings.Encoding.WebName == ValidatingBEUTF16.WebName))

    {

        XmlDictionaryWriter writer = XmlDictionaryWriter.CreateTextWriter(stream, this.m_writerSettings.Encoding, false);

        message.WriteMessage(writer);

        writer.Close();

    }

    else

    {

        XmlWriter writer = XmlWriter.Create(stream, this.m_writerSettings);

        message.WriteMessage(writer);

        writer.Close();

    }

}

Published Sun, May 6 2007 23:21 by Paulo Morgado

Filed under: , , , , , ,

Comments

# Optimizing reading for the CustomTextMessageEncoder@ Monday, May 07, 2007 3:45 PM

Continuing the improvement of the CustomTextMessageEncoder (see this and this ), this time I&#39;ll use

Paulo Morgado

# Optimizing writing for the CustomTextMessageEncoder@ Monday, May 07, 2007 5:01 PM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com

Leave a Comment

(required) 
(required) 
(optional)
(required)