Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to read ConnectStream in HttpWebReqest
    text
    copied!<p>I'm running into a wall when trying to read underlying streams of either HttpWebRequest and HttpWebResponse classes. As it turns out, these are not memory streams; they are of type ConnectStream. The problem with this type of stream is that it doesn't support reading, writing, seeking, nothing. Every time I try to do something with this type of stream I get not supported exceptions.</p> <p>Is there a way to use some other type of stream in place of ConnectStream that would actually be readable?</p> <p>Code:</p> <pre><code>public class BaseAsmxProxy : SoapHttpClientProtocol { protected override System.Xml.XmlReader GetReaderForMessage(SoapClientMessage message, int bufferSize) { string responseXml = GetResponseDataFromStream(message.Stream); return base.GetReaderForMessage(message, bufferSize); } private string GetResponseDataFromStream(System.IO.Stream stream) { string returnValue = null; long initialPosition = stream.Position; stream.Seek(0, SeekOrigin.Begin); StreamReader reader = new StreamReader(stream); returnValue = reader.ReadToEnd(); stream.Seek(initialPosition, SeekOrigin.Begin); return returnValue; } } </code></pre> <p>Note that when I use a SoapExtension (for some other functionality) it switches stream types and I inadvertently get MemoryStream here that is actually readable - which is exactly what I need. However, I'll have to turn off SoapExtentensions at some point and that's where the problems start to occur: ConnectStream is simply not readable.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload