Disabling Keep-Alive

Discussion in 'ASP .Net Web Services' started by Mantorok, Jun 18, 2007.

  1. Mantorok

    Mantorok Guest

    Hi

    ASP.Net v2.0

    I'm referencing a web-service from an ASP.Net web-site. Occasionally, I get
    an intermittent error when accessing the web-service:
    System.Web.HttpUnhandledException: Exception of type
    'System.Web.HttpUnhandledException' was thrown. --->
    System.Net.WebException: The underlying connection was closed: An unexpected
    error occurred on a receive. ---> System.IO.IOException: Unable to read data
    from the transport connection: An existing connection was forcibly closed by
    the remote host. ---> System.Net.Sockets.SocketException: An existing
    connection was forcibly closed by the remote hostI've been advised to try
    disabling Keep-Alive.How can this be achieved?ThanksKev
    Mantorok, Jun 18, 2007
    #1
    1. Advertising

  2. Hi Mantorok,

    As for the webservice proxy, if you're using ASP.NET web site application
    to generate the proxy, you do not have the underlying auto-generated code
    as it will be dynamically generated and compiled at runtime. And you will
    not be able to access the internal webrequest object this way. You can
    consider manually use wsdl.exe to create the web proxy or use a separate
    class library project to create the webservice proxy. Thus, you can access
    the autogenerated source code of the webservice proxy and do some
    customization on the code. The webservice proxy class has a
    "GetWebRequest" protect method that can help you get the underlying
    webrequest object, you can try converting the webrequest to HttpWebRequest
    and configure the KeepAlive property. e.g.

    ==========================

    [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.o
    rg/HelloWorld", RequestNamespace="http://tempuri.org/",
    ResponseNamespace="http://tempuri.org/",
    Use=System.Web.Services.Description.SoapBindingUse.Literal,
    ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    public string HelloWorld() {
    WebRequest request = this.GetWebRequest(this.Url);
    HttpWebRequest httpreq = request as HttpWebRequest;

    httpreq.KeepAlive = false;
    ..............
    ======================

    BTW, for the problem you met, since it occurs occasionally, I think you can
    still do some further check to see whether it may be caused by some
    server-side service unavailable or exception.

    If there is anything else you wonder, please feel free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jun 19, 2007
    #2
    1. Advertising

  3. Mantorok

    Mantorok Guest

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Mantorok,
    >
    > As for the webservice proxy, if you're using ASP.NET web site application
    > to generate the proxy, you do not have the underlying auto-generated code
    > as it will be dynamically generated and compiled at runtime. And you will
    > not be able to access the internal webrequest object this way. You can
    > consider manually use wsdl.exe to create the web proxy or use a separate
    > class library project to create the webservice proxy. Thus, you can access
    > the autogenerated source code of the webservice proxy and do some
    > customization on the code. The webservice proxy class has a
    > "GetWebRequest" protect method that can help you get the underlying
    > webrequest object, you can try converting the webrequest to HttpWebRequest
    > and configure the KeepAlive property. e.g.
    >
    > ==========================
    >
    > [System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.o
    > rg/HelloWorld", RequestNamespace="http://tempuri.org/",
    > ResponseNamespace="http://tempuri.org/",
    > Use=System.Web.Services.Description.SoapBindingUse.Literal,
    > ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
    > public string HelloWorld() {
    > WebRequest request = this.GetWebRequest(this.Url);
    > HttpWebRequest httpreq = request as HttpWebRequest;
    >
    > httpreq.KeepAlive = false;
    > .............
    > ======================


    Thanks very much for this, I've generated the proxy and overriden the
    method, I will see if this makes a difference.

    > BTW, for the problem you met, since it occurs occasionally, I think you
    > can
    > still do some further check to see whether it may be caused by some
    > server-side service unavailable or exception.


    What else would I be able to check? I would be very grateful if you have any
    further suggestions, I always find diagnosing problems like these a bit of a
    nightmare.

    Thanks
    Kev
    Mantorok, Jun 19, 2007
    #3
  4. Thanks for your reply Kev,

    Yes, I agree that such scenario is quite hard to troubleshoot as the
    network issue is not quite stable and reproducable. Currently, I still
    suggest you check whether the server-side service will ocassionally
    break(due to some internal issue or exception) that make the webservice
    call/connection be ended unexpectedly.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jun 21, 2007
    #4
  5. Hi Kev,

    Have you got any progress on this issue? And have you tried monitoring the
    server-side service to see any exceptional behavior that may related to the
    client-side problem? If there is anything else we can help, please feel
    free to post here.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jun 25, 2007
    #5
  6. Mantorok

    Ken Wessel Guest

    this.GetWebRequest() returns null

    Hi Steve,

    I have tried using your code suggestion to set Keep-Alive for a web service "client side"

    Uri uri = new Uri(this.Url);
    WebRequest request = this.GetWebRequest(uri);
    HttpWebRequest httpreq = request as HttpWebRequest;
    httpreq.KeepAlive = false;

    My client class was generated by wsdl.exe

    Unfortunately the WebRequest object "request" has always been null on the return from this.GetWebRequest.

    I tried using the this.GetWebRequest in the constructor and a client web service operation call which of course are both inside of the wsdl.exe code (both times the "request" came back null)

    Do you know where the this.GetWebRequest(uri) call can be used to get an valid instance of WebRequest in a web service client object?

    Thanks,
    Ken Wessel


    EggHeadCafe.com - .NET Developer Portal of Choice
    http://www.eggheadcafe.com
    Ken Wessel, Jun 30, 2007
    #6
  7. Mantorok

    Mantorok Guest

    Hi Steven

    The application appears to be behaving itself now, I successfully disabled
    Keep-Alive and that seems to have made a big difference.

    Thanks
    Kev

    "Steven Cheng[MSFT]" <> wrote in message
    news:...
    > Hi Kev,
    >
    > Have you got any progress on this issue? And have you tried monitoring the
    > server-side service to see any exceptional behavior that may related to
    > the
    > client-side problem? If there is anything else we can help, please feel
    > free to post here.
    >
    > Sincerely,
    >
    > Steven Cheng
    >
    > Microsoft MSDN Online Support Lead
    >
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    > rights.
    >
    Mantorok, Jul 3, 2007
    #7
  8. Mantorok

    Mantorok Guest

    Re: this.GetWebRequest() returns null

    > WebRequest request = this.GetWebRequest(uri);

    Shouldn't this be - base.GetWebRequest(uri);

    Kev

    <Ken Wessel> wrote in message news:...
    > Hi Steve,
    >
    > I have tried using your code suggestion to set Keep-Alive for a web
    > service "client side"
    >
    > Uri uri = new Uri(this.Url);
    > WebRequest request = this.GetWebRequest(uri);
    > HttpWebRequest httpreq = request as HttpWebRequest;
    > httpreq.KeepAlive = false;
    >
    > My client class was generated by wsdl.exe
    >
    > Unfortunately the WebRequest object "request" has always been null on the
    > return from this.GetWebRequest.
    >
    > I tried using the this.GetWebRequest in the constructor and a client web
    > service operation call which of course are both inside of the wsdl.exe
    > code (both times the "request" came back null)
    >
    > Do you know where the this.GetWebRequest(uri) call can be used to get an
    > valid instance of WebRequest in a web service client object?
    >
    > Thanks,
    > Ken Wessel
    >
    >
    > EggHeadCafe.com - .NET Developer Portal of Choice
    > http://www.eggheadcafe.com
    Mantorok, Jul 3, 2007
    #8
  9. Re: this.GetWebRequest() returns null

    Hi Kev,

    Thanks for your followup. Glad that you've made progress through the change
    and also thanks for sharing the result to us.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Steven Cheng[MSFT], Jul 4, 2007
    #9
    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. Luiz Alberto Gibson da Costa

    web chat development, http header connection: keep-alive

    Luiz Alberto Gibson da Costa, Aug 6, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    604
    Luiz Alberto Gibson da Costa
    Aug 6, 2003
  2. twscott
    Replies:
    1
    Views:
    5,041
  3. Herman

    Keep JVM alive with JNI

    Herman, May 24, 2004, in forum: Java
    Replies:
    6
    Views:
    1,107
    Herman
    May 27, 2004
  4. Naresh Agarwal
    Replies:
    1
    Views:
    1,051
    ExGuardianReader
    May 29, 2004
  5. hisan
    Replies:
    1
    Views:
    1,317
    Dan Stromberg
    Jun 25, 2012
Loading...

Share This Page