Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8582565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:19:24+00:00 2026-06-11T21:19:24+00:00

I am trying to modify response from a Web Service using a ClientMessageInspector. At

  • 0

I am trying to modify response from a Web Service using a ClientMessageInspector. At some point I need to create a Message from a modified XMLStream. The content of the stream is below:

<soapenv:Envelope xmlns:soapenv="http://env" xmlns:xsd="http://xsd" xmlns:xsi="http://xsi" xmlns:v1="http://v1">
    <soapenv:Body>
        <v1:VM>
            <SH>
                <a>aa</a>
                <b>bb</b>
            </SH>
        </v1:VM>
    </soapenv:Body>
</soapenv:Envelope>

I try to create the message using:

System.Xml.XmlReader XMLReader = System.Xml.XmlReader.Create(XMLStream);
Message ModifiedReply = System.ServiceModel.Channels.Message.CreateMessage(OriginalReply.Version, null, XMLReader);

However when I print the Message content with Message.ToString() I get:

<s:Envelope xmlns:s="http://env">
    <s:Header />
        <s:Body>
            ... stream ...
        </s:Body>
</s:Envelope>

How can I prevent “…stream…” and get the actual XML parts?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:19:25+00:00Added an answer on June 11, 2026 at 9:19 pm

    A message when created from a XmlReader will always print out ...stream... as its body. Since the reader is a forward-only view on the underlying XML, it cannot be consumed multiple times, so if ToString were to read the data from the reader, the message wouldn’t be able to be used by the rest of the WCF pipeline (such as the encoder, which would write it to the wire).

    What you can do, if you really want to see the full message, is to buffer the message yourself, then recreate it later. You can use a MessageBuffer for that. And if you really want the full message contents, ToString may or may not give it to you, so you need to write the message out to force it to be printed.

    public class StackOverflow_12609525
    {
        public static void Test()
        {
            string xml = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""
                xmlns:xsd=""http://xsd""
                xmlns:xsi=""http://xsi""
                xmlns:v1=""http://v1"">
            <soapenv:Body>
                <v1:VM>
                    <SH>
                        <a>aa</a>
                        <b>bb</b>
                    </SH>
                </v1:VM>
            </soapenv:Body>
        </soapenv:Envelope>";
            MemoryStream XmlStream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
            XmlReader reader = XmlReader.Create(XmlStream);
            Message originalReply = Message.CreateMessage(reader, int.MaxValue, MessageVersion.Soap11);
            Console.WriteLine(originalReply); // this shows ...stream...
            Console.WriteLine();
    
            XmlStream = new MemoryStream(Encoding.UTF8.GetBytes(xml));
            reader = XmlReader.Create(XmlStream);
    
            Message modifiedReply = Message.CreateMessage(reader, int.MaxValue, originalReply.Version);
            MessageBuffer buffer = modifiedReply.CreateBufferedCopy(int.MaxValue); // this consumes the message
    
            Message toPrint = buffer.CreateMessage();
            MemoryStream ms = new MemoryStream();
            XmlWriterSettings ws = new XmlWriterSettings
            {
                Indent = true,
                IndentChars = "  ",
                OmitXmlDeclaration = true,
                Encoding = new UTF8Encoding(false)
            };
            XmlWriter w = XmlWriter.Create(ms, ws);
            toPrint.WriteMessage(w);
            w.Flush();
            Console.WriteLine(Encoding.UTF8.GetString(ms.ToArray()));
    
            modifiedReply = buffer.CreateMessage(); // need to recreate the message here
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to modify the content of the response from some actions in Symfony
I'm trying to use a web service to store/retrieve info from a remote SQL
I need to remove/modify some of HttpServletRequest parameters. I'm trying to do so by
I am trying to modify an Integer field on existing table from nullable to
I am trying to modify the code below to check the input from a
I am trying to modify a status flag in an XML structure using Javascript.
I've been trying to modify this method from redirecting and returning the contents of
I am trying create a small web application that allows a user to login
I'm trying to create/modify dotclear blogs. For most of the options, I use XmlRpc
I’m trying to write a response from a Solr server to a CSV file.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.