ChainStream() in SoapExtension

  • Thread starter Vincent xu via .NET 247
  • Start date
V

Vincent xu via .NET 247

public override Stream ChainStream(Stream stream)
{
oldStream = stream;
newStream = new MemoryStream();
return newStream;
}
When I use this method, it occurs a mistake.
At the BeforeDeserialize stage, oldStream accepts the right stream. It works well.
But at the AfterSerialize stage, the stream passed into the method as following made me sad:

stream {System.Web.Services.Protocols.SoapExtensionStream}
System.MarshalByRefObject {System.Web.Services.Protocols.SoapExtensionStream}System.MarshalByRefObject
Length <error: an exception of type: {System.InvalidOperationException} occurred> long
Null {System.IO.Stream.NullStream} System.IO.Stream
Position <error: an exception of type: {System.InvalidOperationException} occurred> long

So when I continue to call the following method, I can't write anything into oldStream.
private void Compress(SoapMessage message)
{
if(message is SoapServerMessage)
{
newStream.Position = 0;
StreamReader reader = new StreamReader(newStream);
StreamWriter writer = new StreamWriter(oldStream);
string UnCompressedString = reader.ReadToEnd();
string CompressedString = MyZipLib.Zip.Deflate(UnCompressedString);
writer.WriteLine(CompressedString);
writer.Flush();
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top