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

  • SEARCH
  • Home
  • 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 6132595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:07:16+00:00 2026-05-23T17:07:16+00:00

I created a WCF Service that I’m passing a stream to on a request.

  • 0

I created a WCF Service that I’m passing a stream to on a request. The client side code looks like this:

  FileInfo fo = new FileInfo("c:/Downloads/test.xml");
        StreamWriter wo = fo.CreateText();

        XmlDocument MyXmlDocument = new XmlDocument();
        MyXmlDocument.Load("C:/DataFiles/Integrations/RequestXML.xml");
        byte[] RequestBytes = Encoding.GetEncoding("iso-8859-1").GetBytes(MyXmlDocument.OuterXml);

        Uri uri = new Uri("http://localhost:63899/MyRESTServiceImpl.svc/Receive");

        HttpWebRequest Request = (HttpWebRequest)WebRequest.Create(uri);

        Request.ContentLength = RequestBytes.Length;

        Request.Method = "POST";

        Request.ContentType = "text/xml";

        Stream RequestStream = Request.GetRequestStream();
        RequestStream.Write(RequestBytes, 0, RequestBytes.Length);
        RequestStream.Close();

        HttpWebResponse response = (HttpWebResponse)Request.GetResponse();
        StreamReader reader = new StreamReader(response.GetResponseStream());
        string r = reader.ReadToEnd();
        //XmlDocument ReturnXml = new XmlDocument();
        //ReturnXml.LoadXml(reader.ReadToEnd());
        response.Close();

        wo.Write(r);

Right now, all I want to do is process the request and then return the XML right back to the client for testing purposes. Here are my IMyRESTServiceImpl.cs and MyRESTServiceImpl.svc.cs code respectively:

[ServiceContract]
public interface IMyRESTServiceImpl
{
    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare)]
    Stream Receive(Stream text);
}


public class MyRESTServiceImpl : IMyRESTServiceImpl
{

    public Stream Receive(Stream text)  
        {  
            string stringText = new StreamReader(text).ReadToEnd();  

            return text;
        }   

}

Basically what’s happening is that the API is returning my XML to me in string tags and using HTML encoding for the < and > signs (& gt; & lt;). I need it to just return the XML to me exactly as it was sent. I’ve debugged it and the XML remains intact on the server side so this is occurring as it’s sent back. Any ideas on how to handle this? Thanks.

  • 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-05-23T17:07:17+00:00Added an answer on May 23, 2026 at 5:07 pm

    The implementation you have doesn’t compile – the method is declared to return a Stream, but it’s returning a String. If you return as a string, it will encode the XML characters; if you don’t want the encoding, return it either as a Stream or as a XmlElement (or XElement).

    Update with example

    This is an example of a method returning a Stream for an arbitrary XML response:

    [WebGet]
    public Stream GetXML()
    {
        string theXml = @"<products>
      <product name=""bread"" price=""1.33">
        <nutritionalFacts>
          <servings>2</servings>
          <calories>150</calories>
          <totalFat>2</totalFat>
        </nutritionalFacts>
      </product>
      <product name=""milk"" price=""2.99">
        <nutritionalFacts>
          <servings>8</servings>
          <calories>120</calories>
          <totalFat>5</totalFat>
        </nutritionalFacts>
      </product>
    </products>";
        WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
        MemoryStream result = new MemoryStream(Encoding.UTF8.GetBytes(theXml);
        return result;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.