web services time out issue

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dorandoran
    New Member
    • Feb 2007
    • 145

    web services time out issue

    http://addressof.com/blog/archive/2004/04/26/637.aspx

    I found the article but I am not sure how and where to implement the code.

    Code:
    Protected Overrides Function GetWebRequest(ByVal uri As System.Uri) As System.Net.WebRequest
     Dim webRequest As Net.HttpWebRequest = CType(MyBase.GetWebRequest(uri), Net.HttpWebRequest)
    webRequest.KeepAlive = False
    Return webRequest
    End Function
    I copied the exact code and put it right under the imports statement on the top of the form code but geting error.
  • dorandoran
    New Member
    • Feb 2007
    • 145

    #2
    This article describs how to implement the code.


    Originally posted by article
    Solving "The underlying connection was closed: An unexpected error occurred on a send." (Webservices)
    UPDATE: For solution when using WSE, see here!

    Sometimes when you invoke a webservice the call fails with the following exception:

    System.Net.WebE xception: The underlying connection was closed: An unexpected error occurred on a send.
    at System.Web.Serv ices.Protocols. WebClientProtoc ol.GetWebRespon se(WebRequest request)
    at System.Web.Serv ices.Protocols. HttpWebClientPr otocol.GetWebRe sponse(WebReque st request)
    at System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String methodName, Object[] parameters)
    at ...

    In some cases the first call to the webservice works just fine, but if in the following few minutes no new call to the webservice is made, the next call would throw the exception shown above. This problem could be solved by altering the generated proxy class; in the GetWebRequest function the KeepAlive property must be set to false. This can be accomplished by following these steps:

    Add a Web Reference using the normal way (if you haven't already added one ofcourse).
    Make sure Show All Files menu item is enable in the Project menu.
    In the Solution Explorer window, navigate to:
    Web References
    <Name of your webservice>
    Reference.map
    Reference.cs (or .vb)
    Open the Reference.cs file and add following code in the webservice proxy class:
    Code:
    protected override System.Net.WebRequest GetWebRequest(Uri uri)
    {
     System.Net.HttpWebRequest webRequest = 
      (System.Net.HttpWebRequest) base.GetWebRequest(uri);
     webRequest.KeepAlive = false;
     return webRequest;
    }
    Last edited by Frinavale; Mar 31 '09, 02:37 PM. Reason: Added quote and linkback

    Comment

    • billat001
      New Member
      • Mar 2009
      • 1

      #3
      You might want to see this page for more details about The underlying connection was closed.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Dorandoran, could you please explain the problem you're facing.
        It seems you are having a problem solving another problem.
        Could you please explain the original problem before you continue to use code that you don't fully understand?

        Thanks,

        -Frinny

        Comment

        Working...