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

[2120 byte] By [DanielHawkins] at [2008-1-5]
# 1

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.

figuerres at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 2

Hi figuerres

Its actually one pc making both calls, and they fire prety much simultaneously. The actual machine its calling into is an SBS 2003 server.

Thanks

Dan

DanielHawkins at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 3

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

DanielRoth at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 4

Yes Please get a netmon trace
http://blogs.msdn.com/dgorti

Or as Daniel says please get a system.net log file

DurgaprasadGorti at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 5

Hi sorry for the delayed response.

I tired to install netmon, but when I look in my windows components in Management and Monitoring Tools, I don't have network monitor listed.

DanielHawkins at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 6

Daniel,

Did you ever figure out what was happening? I am experiencing something similar when I call a Java based webservice. Most of the time it works fine, but maybe 10% of the time I get the "The request was aborted: The request was canceled." error.

birch9397 at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 7
Heya Folks,
Did either of you resolve this? I have a similar issue (also calling a Java web service) from a .net client.
Thanks in advance,
Billy
webxtasy at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 8

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

DanielHawkins at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 9
I opened a ticket with MSDN support for this problem. The person helping me took a bunch of crash dumps from a test application that reproduces this problem. I got a response this morning, but I haven't had a chance to digest it. I'll post what we discover up here.
birch9397 at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 10

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

birch9397 at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 11
One more follow-up. I implemented the KeepAlives = FALSE and everything seems to be working great.
birch9397 at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 12

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.

Carter33 at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 13
Friday, February 02, 2007 2:15 PM by Craig Scheets

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!!

Antzone at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...
# 14

I'm having this same issue but my client is a BizTalk orchestration and is using the SOAP adaptor. When a web reference is added to a BizTalk project the proxy file is a XSD file instead of a CS file. The problem is I'm not sure how to override a method in a XSD file. And the SOAP adaptor does the instantiation so we have no control over it. So, I'm not sure how to implement the above solution within a BizTalk project.

CharlesGray at 2007-10-3 > top of Msdn Tech,.NET Development,.NET Framework Networking and Communication...

.NET Development

Site Classified