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 6886773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:48:05+00:00 2026-05-27T05:48:05+00:00

I am calling a webservice, which returns a xml with about 2MB. Everything quite

  • 0

I am calling a webservice, which returns a xml with about 2MB.

Everything quite standard. The Problem is the creation of a XDocument.

XDocument xdoc = XDocument.Load( XMLReader Object); // takes 4 sec!!!

I am creating xdoc because I use LINQ to XML to read the XML.

Stopwatch s = new Stopwatch();

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(MyUri);
System.Net.ServicePointManager.Expect100Continue = false;
req.Method = "POST";

req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = Poststring.Length;

StreamWriter swriter = new StreamWriter(req.GetRequestStream());
swriter.Write(Poststring);
swriter.Close();

s.Start();
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
XmlReader MyXmlReader = null;

XmlReaderSettings settings = new XmlReaderSettings();
settings.ProhibitDtd = false;
settings.ValidationType = ValidationType.None;
settings.ConformanceLevel = ConformanceLevel.Document;

Stream stream = response.GetResponseStream();
s.Stop(); 
Debug.WriteLine("stream= response.GetResponseStream(): " + s.ElapsedMilliseconds);
s.Reset();

MyXmlReader = XmlReader.Create(stream, settings);

Debug.WriteLine("Before XDocument.Load(MyXmlReader): " + s.ElapsedMilliseconds);
s.Start();
XDocument xdoc = XDocument.Load(MyXmlReader);
s.Stop();
Debug.WriteLine("Duration: " + s.ElapsedMilliseconds);

The PC is 2 years old, 4 GB RAM. The PC is ok. I tested it on 2 other PCs and Laptop and got same results. My way of the creation of XDocument xdoc takes just to long, but why?

I tested

XDocument xdoc = XDocument.Load(String with path to the same xmlFile on my pc);

and it took like 20 Milliseconds.

EDIT:
here some timings:

stream= response.GetResponseStream(): 5276 Milliseconds

I guess this is the time from Server to my pc

Duration: 4855

time needed for: XDocument xdoc = XDocument.Load(MyXmlReader);

Maybe a problem because it is Stream beeing “converted” into XDocument xdoc object?

edit2: I just tested

HttpWebResponse response = (HttpWebResponse)req.GetResponse();
MemoryStream ms = new MemoryStream();

//responsetime from server to my pc: 6000 ms
Stream stream = response.GetResponseStream(); 
stream.CopyTo(ms); //this operation takes 4000 ms!!!
ms.Position = 0;
XDocument x4 = XDocument.Load(ms);// this takes 13 ms!!!

The conversion of the data in the stream object to some useful data(like string or ms) take that long, but why?

Am I right, that all data from Web-service are 100% sent and have arrived and only then the next line of code is beeing performed? or is stream.copyTo(ms) operating on a stream that is open and still receiving data?

  • 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-27T05:48:06+00:00Added an answer on May 27, 2026 at 5:48 am

    In the line:

    MyXmlReader = XmlReader.Create(stream, settings);
    

    You are reading from a Stream, which is essentially a pipe, not a bucket; the stream does not yet have all that data. I’m guessing that 2MB is taking about 4 seconds to arrive down the wire.

    If that is too long, make sure you have enabled gzip/deflate on the http connection. As oberfreak notes, there are other data formats that are more suited to large documents (xml can become unwieldy at large sizes, although it will generally work).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling a webservice which return me back a json object. The json
I using Flash builder 4.5 and calling my own webservice which return a json
I'm using javascript to submit a form to a webservice which returns a json
I am currently calling a web service that returns a service defined class which
I have been given the task of calling a web service which returns an
I am getting this error when calling a web service method which writes to
I'm calling a webservice using the NuSoap PHP library . The webservice appears to
I'm calling a WebService exposed by Oracle that accepts an input of an ItemID
I'm calling a webservice that is returning an unknown quantity of images in the
I am calling a webservice and I am getting a complex object back. I

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.