MessageEncoder 类的用法 RRS feed

  • 问题

  • 各位大神,请问一下MessageEncoder 类的WriteMessage (Message^, Int32, BufferManager^, Int32)方法和ReadMessage  (ArraySegment<Byte>, BufferManager^, String^)类怎么用
    public override ArraySegment<byte> WriteMessage(Message message, int maxMessageSize, BufferManager bufferManager, int messageOffset)
                MemoryStream stream = new MemoryStream();
                XmlWriter writer = XmlWriter.Create(stream, this.writerSettings);
                byte[] messageBytes = stream.GetBuffer();
                int messageLength = (int)stream.Position;
                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 Message ReadMessage(ArraySegment<byte> buffer, BufferManager bufferManager, string contentType)
                byte[] msgContents = new byte[buffer.Count];
                Array.Copy(buffer.Array, buffer.Offset, msgContents, 0, msgContents.Length);
                MemoryStream stream = new MemoryStream(msgContents);
                return ReadMessage(stream, int.MaxValue);


    WriteMessage return的byteArray 和ReadMessage 传入的buffer不一样是为什么呀? 
    2016年3月16日 7:14


  • 你好 Riven,

    >>请问一下MessageEncoder 类的WriteMessage (Message^, Int32, BufferManager^, Int32)方法和ReadMessage  (ArraySegment<Byte>, BufferManager^, String^)类怎么用

    这个类是用于编码信息的。 正好找到一个详细讲解WCF中编码相关的内容,请移步。

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    2016年3月17日 5:58