Exception in web service client from EndInvoke with compressed WebResponse

M

Mike Henderson

I'm having trouble decompressing a stream asynchronously in my web
service client application. I'm using a proxy class derived from the
SoapHttpClientProtocol class. I have a CompressedHttpWebResponse
wrapper class to decompress the gzip responses that I get from the
server. It's derived from WebResponse and overrides the
GetResponseStream() method to return the the decompressed stream.
Everything works perfectly when I call my web methods synchronously,
but when I call them asynchronously I get the following exception when
calling the MyWebService.EndMyMethod() portion of the async web
method:

System.ArgumentNullException: Value cannot be null.
Parameter name: stream
at System.IO.StreamReader..ctor(Stream stream, Encoding encoding,
Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtocol.EndInvoke(IAsyncResult
asyncResult)
at MyWebService.EndMyMethod(IAsyncResult asyncResult)


The code that I added to the SoapHttpClientProtocol derived class is
as follows:


protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest
(uri);
webRequest.Headers.Add("Accept-Encoding","gzip");
webRequest.KeepAlive = false;

return webRequest;
}

protected override WebResponse GetWebResponse(WebRequest request,
IAsyncResult result)
{
WebResponse response = base.GetWebResponse(request,result);
CompressedHttpWebResponse compressedResponse = new
CompressedHttpWebResponse(response as HttpWebResponse);
return compressedResponse;
}


protected override WebResponse GetWebResponse(WebRequest request)
{
WebResponse response = base.GetWebResponse (request);
CompressedHttpWebResponse compressedResponse = new
CompressedHttpWebResponse(response as HttpWebResponse);
return compressedResponse;
}

Even without compression, I get the exception when I return my wrapper
class and not an HttpWebResponse from GetWebResponse, so the EndInvoke
must only be able to handle HttpWebResponse.

I looked at the WebClientAsyncResult that the callback method
receives. It has an internal stream property called 'Buffer'. When I
make the async GetWebResponse call return the result of
base.GetWebResponse() this property has a valid value, but it is null
when I return my CompressedHttpWebResponse. Could this be what is
causing the error? I can't figure out anyway to set it...
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top