I’m using XML-RPC.NET (from http://www.xml-rpc.net/) and the HttpListener method of listening for XML-RPC communication on a specific network port and responding to it.
The body of a request that comes in is accessible through the HttpListenerContextInstance.Request.InputStream Stream object:
HttpListener hlListener = new HttpListener();
HttpListenerContext hlcContext = hlListener.GetContext();
// hlcContext.Request.InputStream contains what I want
The Stream can be accessed from hlcContext.Request.InputStream but this Stream is not seekable so I can’t read it/display it and then seek back to the beginning of it so that the XML-RPC.NET library can use it as it needs to. Once it’s read, it’s consumed and can’t be re-read.
I understand that one way of handling this situation would be to convert it from a Stream into a MemoryStream which does support seeking, however, I don’t know of a way to do this so that XML-RPC.NET continues on using the MemoryStream instead of the Stream. Just copying the Stream to a MemoryStream seems to consume the Stream making it unusable past that point:
// hlcContext.Request.InputStream is currently filled
MemoryStream msInput = new MemoryStream();
hlcContext.Request.InputStream.CopyTo(msInput);
byte[] byteInput = msInput.ToArray();
// hlcContext.Request.InputStream is now empty and XML-RPC.NET can no longer use it :(
How can I read from the Stream so that I can store it in a String and have the Stream continue to work with XML-RPC.NET after that point?
If you can’t find a legitimate way, here is a hack to set a stream to
Request.InputStream(As a last resort)Now you can freely use
byteInput