Simultaneous calls to services results in The request was aborted: The request was canceled
Hi Everyone
I am making simultaneous calls to seperate web services on the same server. The services have WSE 3 enabled using certificate based security.
After a minute or so of running one them returns with the error "The request was aborted: The request was canceled", I am completley stumped, if I just make one of the calls then everything is ok. Here is the stack trace from the exception:
at System.Net.ConnectStream.InternalWrite(Boolean async, Byte[] buffer, Int32 offset, Int32 size, AsyncCallback callback, Object state)
at System.Net.ConnectStream.Write(Byte[] buffer, Int32 offset, Int32 size)
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
at System.IO.StreamWriter.Write(String value)
at System.Xml.XmlTextWriter.WriteStartElement(String prefix, String localName, String ns)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlElement.WriteContentTo(XmlWriter w)
at System.Xml.XmlElement.WriteTo(XmlWriter w)
at System.Xml.XmlDocument.Save(XmlWriter w)
at Microsoft.Web.Services3.SoapEnvelope.Save(Stream outStream)
at Microsoft.Web.Services3.Messaging.SoapPlainFormatter.Microsoft.Web.Services3.Messaging.ISoapFormatter.Serialize(SoapEnvelope envelope, Stream stream)
at Microsoft.Web.Services3.Xml.SoapEnvelopeWriter.Finish()
at Microsoft.Web.Services3.Xml.XmlWrappingWriter.Flush()
at System.Web.Services.Protocols.SoapHttpClientProtocol.Serialize(SoapClientMessage message)
at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
at Washtec.Win.ServiceAgents.JobWS.JobsWSWse.GetTodaysJobs() in
Any help on this is would be much appreciated, I'm using Visual Studio 2005, and the services were also built using visual studio 2005.
Thanks in advance.
Dan
do you mean "One client pc calling the same service multiple times"
or "two or more client pc's calling the service at the same time" ?
if one client tries to open more than 2 connections to a web server it can be halted by the way HTTP works. by default http wants only 2 connections per client to keep from having a few clients flood a server with requests.
if you have 2 or more clients calling the same web method then perhaps the method is blocking the other calls -- for example a sql data call innthe method is taking to long.
also if the web server is iis on xp pro that has a connection limit on it that could block calls. if thats the case google for the subject and you wil find some ways to up xp pro to about 39 connections.
This sounds like a networking issue, so I'm going to move this thread to the networking web forum.
Basically what is happening is one of the services is closing the connection when the client expects it to still be open. You should consider getting a network trace to see what is going on on the wire:
http://msdn2.microsoft.com/en-us/library/a6sbz1dx.aspx
Daniel Roth
Hi
I never did find a proper answer to the problem in the end I had to just make the calls one after the other as each finished, which is a real pain.
If anyone does have an answer for this then I am still interested as well.
Sorry I can't be of much help
Dan
OK, I got a chance to digest the response. I'll post it below. The response included a suggestion to try. I did, and it seems to fix the problem. I don't know if there will be other consequences to the app, but we're making progress:
Here's the response:
I’ve finally been able to review the crash dump of the Request Canceled exception that you are getting. It turns out that when you start to make spin up your second set of threads to call the remote web service your ASP.NET application is waiting for a response from the web service but instead the web server resets the connection. Within the dump that I collected we see that there is an exception with the text of “The underlying connection was closed: A connection that was expected to be kept alive was closed by the server”. It appears that the code logic in .NET 2.0 is that when this occurs we will try to resend the web request, however because of the previous exception the m_Aborted property of the HttpWebRequest object is set to true and so we end up getting the Request Canceled exception that you are seeing.
So it appears that the BEA WebLogic web server is resetting the connection, whereas the ASP.NET application expects the connection to still be active. I cannot explain why you do not see this problem in .NET 1.1. We will need to capture a set of network traces in order to help determine this.
Action Plan
==================
We do not have an explanation of why your BEA WebLogic web server is resetting, thus closing, the connection with your ASP.NET application, and I currently can’t explain why you don’t see similar symptoms with your .NET 1.1 application that runs the same code. For our next troubleshooting steps I’d like for you to disable Http KeepAlives for the HttpWebRequest object in your .NET 2.0 application. This will force the client to establish another TCP session with the BEA Web server before sending out another web service requests.
In order to set the KeepAlive property of the HttpWebRequest object to false you will need to override the GetWebRequest method within your client application. Please see Resolution D in the following article to see how to do this in your ASPX client page
915599 You receive one or more error messages when you try to make an HTTP request in an application that is built on the .NET Framework 1.1 Service Pack 1
http://support.microsoft.com/default.aspx?scid=kb;EN-US;915599
Well, we actually tried this solution without success :-( Only difference was that we implemented the GetWebRequest override in a WSE enabled proxy class. (IE, we wrote our web service classes, enabled WSE on them and then derived a new class from the proxy class that was generated with the WSE)
Anyone who might have any other ideas as to why it still fails for us would be greatly appreciated.
Paul.
THE REAL ASP.NET 2.0 SOLUTION:
I fought this for a while and finally got the right code to fix this problem in ASP.Net 2.0. As many of you know, ASP.Net 2.0 generates the proxy classes dynamically so you can't just simply edit them. The key is in a new feature, 'partial classes'. Below is everything you need to know to fix this in ASP.Net 2.0.
First, my web reference declaration is:
weather.ndfdXML
The standard instantiation would then look like:
weather.ndfdXML2 wxService = new weather.ndfdXML2();
With this setup, I ran into the exact same problem everyone else has written about here and rarely solved.
First, add a new class and make it a partial class (C# code posted):
using System;
using System.Net;
using System.Web.Services.Protocols;
namespace weather
{
public partial class ndfdXML2 : weather.ndfdXML
{
protected override System.Net.WebRequest GetWebRequest(Uri uri)
{
//throw new Exception("Custom WebRequest override code hit!!");
System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = HttpVersion.Version10;
return webRequest;
}
}
}
You can optionally uncomment that new exception to verify that the code is indeed executing.
Second, change you instantiation inside your code to the following:
weather.ndfdXML2 wxService = new weather.ndfdXML2();
Now everything works great!!