Jun 03, 2013 10:19 PM|Amy Peng - MSFT|LINK
When occur the below problem, you must explicitly set the KeepAlive property to FALSE so that the connection will be closed by itself and re opened for every request. This will avoid the issue of attempting to use a closed connection.
There is no direct way you can set the KeepAlive to FALSE. This is a 'Protected' property on the WebRequest. When you use web services, you must first derive a class from your webservice class and then set this flag to FALSE in the inherited class.
Assume you have a web reference with the name 'Banking' and a webservice class called 'Transaction'. Typically, you will use the class as follows in your client:
dim obj as new Banking.Transaction()obj.MakeTransaction()
To set the KeepAlive property, you must inherit a class from Banking.Transaction in your client. Create a new class called "BankTransaction" in the client project. Now inherit the "GetWebRequest" method in this class as shown below:
Public Class BankTransaction Inherits Banking.Transaction Protected Overrides Function GetWebRequest(ByVal uri As Uri) As System.Net.WebRequest Dim webRequest As System.Net.HttpWebRequest webRequest = CType(MyBase.GetWebRequest(uri), System.Net.HttpWebRequest) ' Setting KeepAlive to false webRequest.KeepAlive = False return webRequest End FunctionEnd Class
We are explicitly setting the property KeepAlive to FALSE in the above inherited method. Now, use the inherited class to make the webservice calls. This will solve the error.
For more information, please try to refer to:
Hope it can help you.