I have a web service running on server but once in a while it throws an error. This is happening when calling one particular method and all other method works fine but on calling this method I receive following error:-
An error occurred while receiving the HTTP response to
https://xxx/xxx/xxx.svc. This could be due to the service endpoint
binding not using the HTTP protocol. This could also be due to an HTTP
request context being aborted by the server (possibly due to the
service shutting down). See server logs for more details.
Currently it happened after running fine for 2 weeks. Strangely the method started working fine again after few hours. I am wondering where should I start looking to troubleshoot this issue? Any pointers to troubleshoot shall be helpful.
Just to add to this today I received below error:-
The underlying connection was closed: A connection that was expected
to be kept alive was closed by the server
Can both of the error be related to each other?
Thanks for the help!
I've also encountered that error.
I encountered that error when almost thousands of user simultaneously accessing the web service.
I put this piece of code..
ServiceClient = new ServiceClient ();
var customBinding = new CustomBinding(ServiceClient.Endpoint.Binding);
var transportElement = customBinding.Elements.Find<HttpTransportBindingElement>();
transportElement.KeepAliveEnabled = false;
ServiceClient.Endpoint.Binding = customBinding;
ServiceClient.Open();
Recently i asked to implement a wcf service.
One of the problems i am facing is how to detect network failure and raise fault exception,
after some research , i found that is it possible to set receive time out property to max value,
and the inactivity to some time span,
basically it works, but my question is am i doing good practice while i doing so?
or anybody have a better way to detect unexpected network failure
I am using tcp binding option
netTcpBind.ReceiveTimeout = TimeSpan.MaxValue;
netTcpBind.CloseTimeout = TimeSpan.MaxValue;
netTcpBind.SendTimeout = TimeSpan.MaxValue;
netTcpBind.ReliableSession.Enabled = true;
netTcpBind.ReliableSession.InactivityTimeout = new TimeSpan(0,2,0);
ReliableSession internally sends infrastructure messages in the specified time interval & verifies whether the TCP session is still alive. This should handle all network related failure errors. Check the below link for details:
http://www.blogs.sigristsoftware.com/marcsigrist/post/Prerequisits-for-implementing-a-keep-alive-mechanism-in-WCF-30.aspx
I have a Winforms appplication written in C# that consumes web services from a Windows 2008 IIS Coldfusion server. All the web service calls succeed but one, which fails about 50% of the time with the following error:
System.InvalidOperationException was unhandled by user code
Message=There is an error in XML document (1254, 7).
with an inner exception of:
InnerException: System.IO.IOException
Message=Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
I checked my IIS logs and I get a 503 error (Service Unavailable) and an IIS code of 64 (The specified network is no longer available). Any suggestions would be great.
I run my web service in SOAP UI and I get the following error:
javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.net.SocketException: Connection reset
This code works fine at one company but this error pops up almost every time for this company I'm currently working with.
I'm not sure this is applicable to the OP's specific situation, but this may help others who arrive here nowadays. One potential cause for this exception involves mismatched security protocols. If the server you're calling requires TLS 1.2 and you're using an older version of ASP.net (<= Version 4.0) you will be using an older security protocol to make your calls unless you change it. You can force ASP.net to use TLS 1.2 (shown below). This can be done anywhere in the application, but I put it just before the line that calls the web service requiring TLS 1.2:
using System.Net;
...
//Enable TLS 1.2
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
// Call the Web Service that requires TLS 1.2
I recently got a similar message when consuming a WCF-Webservice. In my case it turned
out to be a configuration error on the server side. Maybe something is configured differently
on the one server where this happens to you?
My problem was that the default maximum message size was configured to be too small
on the server and this resulted in the same forced connection closing. There is a default
maximum message size to avoid DOS attacks...
If you are using a WCF client to connect to the service, enable service trace logging in your client application with the following config:
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel"
switchValue="Error"
propagateActivity="true">
<listeners>
<add name="sdt"
type="System.Diagnostics.XmlWriterTraceListener"
initializeData= "ErrorTrace.svclog"
/>
</listeners>
</source>
</sources>
</system.diagnostics>
Download the windows sdk and you have a nice trace viewer for these log files. It helps you get to the bottom of errors in WCF communication.
Using cross platform communication sometimes it happens (once happened to my code) that the exception thrown is not the real description of what is happening inside.
One cause of this exception is that your response time is a little lesser than time required by the webservice method to complete. So try to increase the timeout in your app.config.
If it doesn't work there could be two possible problems in your case.
If SSL is used then there is problem with SSL certificate validity.
There are some invalid characters used in XML for example your platform doesn't support Unicode characters and there is some un-supported character used in XML.
But I hope just increasing the timeout will fix this.
I did get similar error and cause was exception in XML serialization. Mostly if xmlserializer tries to read some property and that get method raises an exception due to some database connection already closed or any resources not available.
Have you tried to log exceptions in error event inside global.asax?
Sometimes if global.asax does not raise error event, then only way to log error through response filter. You can add custom response filter in the web.config, in which you will be able to analyze how much XML was correctly serialized and where it might be failing.
http://msdn.microsoft.com/en-us/library/aa479332.aspx
http://www.raboof.com/projects/elmah/
Intermediate "An existing connection was forcibly closed by the remote host" from only one destination sounds like a networking issue to me.
Try getting logs from the server you try to access and from the involved firewalls of both locations.
You may run Fiddler or NetMon / WireShark / Ethereal to diagnose further.
Connection close happen for any circumstance. Make sure the timeout is abundant on the server and the client, make sure there is no recursion in the data you are returning. Circular reference. Serialization is important in this case because the thing is being serialized when returned.
Do a WCF tracer and check the answer there. Any fault in the server will close the connection. If the server requires username, make sure those are correct. Take care of the SSL error. use WCF client to test the service.
This may be a shot in the dark but here is my theory:
The first error is happening on the web service side with a poor exception being thrown, maybe some invalid data is being passing into the service? This could return the error regarding the XML being malformed. I would do several test cases to see what data is being passed into the service and what causes the issue.
The second error I have seen before in a certain circumstance regarding a web service exception being thrown and a try catch wrapped around a using statement for the service. This combination of logic caused an early exit that wasnt cleaned up.
try to check the existing protocols in your last company and compare them with your current company,I mean TCP/Ip,...
Check the app pool recycling configuration in IIS. I have seen this error, for example, when the "Private Memory Limit" is set to a value (say 100mb) and then the w3wp process exceeds this limit which will cause the app pool to be recycled.
This normally isn't a problem since any existing connections are given time to complete and new connections will be processed by the newly spun-up app pool.
If all the connections are not closed within the shutdown time limit though (normally 90 seconds) then they are killed by IIS and the client may raise the "An existing connection was forcibly closed" error.
I have the following WCF client code:
string add = String.Format("http://localhost:{0}/ServiceRequestRest",accessPort);
var cf = new ChannelFactory<IServiceRequestRest>(new WebHttpBinding(), add);
cf.Endpoint.Behaviors.Add(new WebHttpBehavior());
busService = cf.CreateChannel();
busService.DoMyStuff("hello",null);
When I have "first chance exception break" activated, that last line of code throws a series of exceptions. The first exception is this:
System.InvalidOperationException occurred
Message="Envelope Version 'EnvelopeNone (http://schemas.microsoft.com/ws/2005/05/envelope/none)' does not support adding Message Headers."
Source="System.ServiceModel"
StackTrace:
at System.ServiceModel.Channels.MessageHeaders.ValidateHeaderKind(HeaderKind headerKind)
I am not aware that I am trying to "add Message Headers", but I choose to continue execution and immediately get the next exception:
System.Net.WebException occurred
Message="The underlying connection was closed: The connection was closed unexpectedly."
Source="System"
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
With all that said, I'm having difficulty understanding what the problem is. Any clues?
Update: The return type of my REST call could not be serialized, as I learned from another site. That alone could cause this problem, but after I fixed it I still had the same problem. When I use a regular catch block for the exception, all I get is "the connection was closed unexpectedly." What else could I be missing?
Update2: I think I found the final problem. I was getting interference from Skype. The code is working now. :)
The main problem that I see is that you are trying to use a WCF Channel to communicate using WebHttpBinding.
IMHO the entire purpose of WebHttpBinding was so that the client did not have to use the WCF stack to communicate with it. You simply use any HTTP stack to make the requests.
I am getting a timeout exception when trying to use a net tcp endpoint through code
that has no security and is streamed like so:
NetTcpBinding binding = new NetTcpBinding(SecurityMode.None);
binding.TransferMode = TransferMode.Streamed;
binding.SendTimeout = TimeSpan.MaxValue;
the same code would work if i just leave out the SecurityMode.None or choose SecurityMode.Transport, the exception is on a timeout that is too low, i tired adding all the timeouts for recive, send, open, close and set them all to Max and that didnt work.
im using sample code from:
http://csharp-codesamples.com/2009/02/data-transfer-using-self-hosted-wcf-service/
Any explenation as to how to use no security in this scenario would be appriciated.
Thanks,
Totem
Sometimes WCF gives the wrong error message.
Only some security modes work when you are using streaming. You cannot sign a message, when you do not know how long it is.
Transport security mode works and is default, therefore it works when you do not specify the transport mode.
http://msdn.microsoft.com/en-us/library/ms731316.aspx