Author |
Message |
Manuel9999

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
Hello,
we very often get the above Exception on our application, which makes strong use of WebServices. Does anybody know, why this Exception can occure and how to avoid it
Kind regards, Manuel
.NET Development4
|
|
|
|
 |
JonCole

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
Can you send the output of webException.ToString()
|
|
|
|
 |
Manuel9999

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
I implemented the following function to debug the WebException:
private void HandleWebException(System.Net.WebException ex) { string logEntry = "No response from Web Service " + Environment.NewLine + ex.ToString(); logEntry += Environment.NewLine + "Status: " + ex.Status; if (ex.InnerException != null) { logEntry += Environment.NewLine + "InnerException: " + ex.InnerException.ToString(); } if (ex.Response != null) { logEntry += Environment.NewLine + "Response.ContentLength: " + ex.Response.ContentLength; logEntry += Environment.NewLine + "Response.ContentType: " + ex.Response.ContentType; if (ex.Response.Headers != null && ex.Response.Headers.Count > 0) { foreach (string s in ex.Response.Headers.AllKeys) { logEntry += Environment.NewLine + "Response.Headers."+s+": " + ex.Response.Headers ; } } if (ex.Response.ResponseUri != null) { logEntry += Environment.NewLine + "Response.ContentType: " + ex.Response.ResponseUri.ToString(); } }
And this is the (poor ) output:
System.Net.WebException: The request was aborted: The request was canceled. at System.Web.Services.Protocols.WebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.HttpWebClientProtocol.GetWebResponse(WebRequest request) at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) at BEWebServices.BBAServiceService.triggerDateOverview(BBADateOverviewRequest in0) in C:\TFSProjects\BEFrontend\BEWebServices\BBAService.cs:line 47 at BEWebServiceConverter.BbaConverter.TriggerOutboundFlightOverview(AdvertisedFlightRequest request, State state) in C:\TFSProjects\BEFrontend\BEWebServiceConverter\BbaConverter.cs:line 45 at BEBusinessLogic.Commands.BbaCommand.TriggerOutboundFlightOverview() in C:\TFSProjects\BEFrontend\BEBusinessLogic\Commands\BbaCommand.cs:line 300 at BEBusinessLogic.Commands.BbaCommand.Execute() in C:\TFSProjects\BEFrontend\BEBusinessLogic\Commands\BbaCommand.cs:line 45 at BEBusinessLogic.Commands.DispatcherCommand.Execute() in C:\TFSProjects\BEFrontend\BEBusinessLogic\Commands\DispatcherCommand.cs:line 133 Status: RequestCanceled
|
|
|
|
 |
JonCole

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
Are you setting a timeout on the WebService call Can you add code to see what amount of time elapses between the time you start the call and when you get the exception
I would expect the error message to state that a timeout happened if it were a timeout causing the problem but I want to make sure this is not the cause.
|
|
|
|
 |
Manuel9999

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
The solution was to disable HTTP Keep Alive for posting the Requests.
|
|
|
|
 |
Azam Abdul Rahim

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
and how do you do that can you please explain
|
|
|
|
 |
JonCole - MSFT

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
HttpWebRequest.KeepAlive = false;
|
|
|
|
 |
Azam Abdul Rahim

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
For the benefit of those who may encounter this problem in the future, here is a more detailed explanation of what needs to be done.
When we add a web reference to a project, VS will generate a file named Reference.cs for the web reference. This file defines a class which inherits the System.Web.Services.Protocols.SoapHttpClientProtocol, and the class contains methods that correspond to the web service methods available on the web reference.
What we need to do is to edit this file and override the inherited GetWebRequest method. The overriding method should look something like this (sample written in C#):
Code Snippet
protected override WebRequest GetWebRequest(Uri uri) { HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false; webRequest.ProtocolVersion = HttpVersion.Version10; return webRequest; }
And remember that when you do an Update Web Reference command, VS will regenerate the file and your changes will be lost. So you will need to override the method again after each update.
|
|
|
|
 |
Manuel9999

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
Also a very good practice is to override the GetWebRequest Method in a base class and change the automatic generated proxy classes to inherit from this base class.
Example base class:
public abstract class BaseService : System.Web.Services.Protocols.SoapHttpClientProtocol
{
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
System.Net. HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
return webRequest;
}
}
|
|
|
|
 |
Mark

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
Manuel9999,
Thanks for posting your code however I have another question.
If I have an aspx 2.0 page that via a vb code behind calls a web service like
Dim objWS as new WS.WS1
strReturn = objWS.function1
but I am not sure how to reference your code. I don't see references.vb in my project and from where I am making this call I already have an inherits statement for something else.
Any help would be appriecated.
Thanks
|
|
|
|
 |
Rory Bannon

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
The easiest way to handle this is to use partial classes.
public partial class SubscriberEvent { protected override WebRequest GetWebRequest(Uri uri) { HttpWebRequest webRequest = (HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false; return webRequest; } }
Makes things much easier.
|
|
|
|
 |
Mark

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
I have a solution to my problem. To recap I have a asp.net 2.0 web application that is making a web service call to a web service hosted by tomcat version 5.5.12. Sometimes I would get the error noted above and it was all related to a configuration setting. .Net 2.0 uses HTTP 1.1 keep alives so that the tcp handshake doesn't need to be established every time a call is made, thus making things faster. However the default http keep alive timeout value in .net is 100 seconds and in my case tomcat's http keep alive timeout was set less than that so tomcat would expire the http keep alive and then when .net would go to use that thread is would be broken thus the thread abort message.
The real solution was to configure tomcat to expire the http keep alives after .net. With this you get the extra performance of http keep alives and no headaches of abort errors.
Hope this helps.
Mark
|
|
|
|
 |
PAsp

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
How do I change the keep alive timeout on Tomcat
I only found the timout on Tomcat version 6 and above.
/Peter
|
|
|
|
 |
Mark

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
Peter,
In the tomcat /conf/server.xml file set the connectionTimeout value (it is in milli seconds). Then restart tomcat and you should be all set. Please see the section I pasted in below.
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 -->
<!-- The port and connectionTimeout was changed from the default. The connectionTimeout is set to 110 seconds to be greater than .Net 2.0 framework of 100 seconds for HTTP Keep Alives -->
<Connector port="8000" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="110000" disableUploadTimeout="true" />
Enjoy.
|
|
|
|
 |
PAsp

|
Posted: .NET Framework Networking and Communication, System.Net.WebException: The request was aborted: The request was canceled. |
Top |
|
|
 |
|