I am calling a web-service with POST and receiving a 2MB xml. The problem is that it takes to much time until i can use the data within the Stream. The response seems to be after 7 secs there, but it takes another 10 sec to read the content(its a string) from response stream.
Stopwatch s = new Stopwatch();
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(MyUri);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = Poststring.Length;
s.Start();
StreamWriter swriter = new StreamWriter(req.GetRequestStream());
swriter.Write(Poststring);
swriter.Close();
// Get the response. 7 sec
HttpWebResponse response = (HttpWebResponse)req.GetResponse();
s.Stop();
Debug.WriteLine("Talking to Web-Service: "+s.ElapsedMilliseconds);
s.Reset();
// Get the stream containing content returned by the server.
Stream dataStream = response.GetResponseStream();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader(dataStream);
// Read the content. 10 sec
XmlReader xmlReader = XmlReader.Create(dataStream);
s.Start();
XDocument xdoc = XDocument.Load(xmlReader);
s.Stop();
Debug.WriteLine("Convert stream to some useful data: "+s.ElapsedMilliseconds);
output in milliseconds
Talking to Web-Service: 6595
"Convert" stream to some useful data: 10772
Why does it take like 10 sec to read the content?? Is there stil some communication with the web-service or waiting for data when content is read? Its just a simple textfile (xml) with about 2MB. I thought that those 2 MB were transfered within the 6596 milliseconds. Because when i call that service with my browser, the xml content is shown in 6-7 sec.
The time for Talking to Web-Service is ok, but what is going on in those 10772 milliseconds?
Edit: The problem is stil there. I get different answers and they contradict each other.