How to get Action Stream from Message RRS feed

  • Question

  • My below fragment code is to create a message with my custom BodyWriter.

    public Message ProcessRequest(Stream messageBody)
                if (Context == null)
                    throw new InvalidOperationException("The data service context cannot be null");
                if (DataSource == null)
                    throw new InvalidOperationException("The data source can not be null");

                Action<Stream> writer = HandleRequest();
                return CreateMessage(MessageVersion.None, string.Empty, Context.ResponseContentType, writer, null);

    private static Message CreateMessage(MessageVersion version, string action, string contentType, Action<Stream> writer, IDataService service)
                DelegateBodyWriter writer2 = new DelegateBodyWriter(writer, service);
                Message message = Message.CreateMessage(version, action, (BodyWriter)writer2);
                HttpResponseMessageProperty property = new HttpResponseMessageProperty();
                property.Headers[HttpResponseHeader.ContentType] = contentType;
                message.Properties.Add(HttpResponseMessageProperty.Name, property);
                return message;

    After creating message, I've got the message. Now I want to get the stream back so that I can make a unit test with the stream.
    Is there anybody know how to do that?


    Thursday, December 11, 2008 4:10 AM


  • I find the solution for this issue.
    In the Message class, there is a method named WriteMessage. I write entire message to a stream.
    From it, I can deserializer the content of the message.


    • Marked as answer by Tai Ly Wednesday, December 17, 2008 7:20 AM
    Wednesday, December 17, 2008 7:20 AM