Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net Web Services (http://www.velocityreviews.com/forums/f64-asp-net-web-services.html)
-   -   Exception in web service client from EndInvoke with compressed WebResponse (http://www.velocityreviews.com/forums/t783894-exception-in-web-service-client-from-endinvoke-with-compressed-webresponse.html)

Mike Henderson 10-14-2004 05:34 PM

Exception in web service client from EndInvoke with compressed WebResponse
 
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.SoapHttpClientProtoc ol.ReadResponse(SoapClientMessage
message, WebResponse response, Stream responseStream, Boolean
asyncCall)
at System.Web.Services.Protocols.SoapHttpClientProtoc ol.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...


All times are GMT. The time now is 10:00 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.