Exception in web service client from EndInvoke with compressed WebResponse

Discussion in 'ASP .Net Web Services' started by Mike Henderson, Oct 14, 2004.

  1. 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...
     
    Mike Henderson, Oct 14, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. chintan jajal via .NET 247

    Delegate Endinvoke Kill thread

    chintan jajal via .NET 247, May 24, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    6,988
    Richard Grimes [MVP]
    Jun 6, 2005
  2. ScottO
    Replies:
    2
    Views:
    562
    ScottO
    Nov 3, 2003
  3. Jeff G.
    Replies:
    3
    Views:
    4,465
    markwebdev
    May 20, 2010
  4. John
    Replies:
    1
    Views:
    822
    Joerg Jooss
    Mar 5, 2005
  5. ad
    Replies:
    6
    Views:
    3,303
Loading...

Share This Page