Error using web service: existing connection was forcibly closed

I have a Winforms application written in C # that uses web services from a Windows Server 2008 IIS Coldfusion server. All web service calls are successful, but one that does not work in about 50% of cases with the following error:

System.InvalidOperationException was not handled by user code Message = There is an error in the XML document (1254, 7).

with internal exception:

InnerException: System.IO.IOException Message = Unable to read data from transport connection: existing connection was forcibly closed by the remote host.

I checked the IIS logs and received error 503 (Service Unavailable) and IIS 64 code (the specified network is no longer available). Any suggestions would be great.

I run my web service in the SOAP user interface and I get the following error:

javax.net.ssl.SSLException: connection completed: javax.net.ssl.SSLException: java.net.SocketException: Connection reset

This code works fine in one company, but this error appears almost every time for this company, with which I now work.

+6
source share
10 answers

I recently received a similar message when using WCF-Webservice. In my case, this turned out to be a server-side configuration error. Maybe something is configured differently on the same server, where does this happen to you? My problem was that the default maximum message size was configured to be too small on the server, and this led to the same forced closing of the connection. By default, the maximum message size to avoid DOS attacks ...

+3
source

If you are using a WCF client to connect to a service, enable service trace logging in your client application with the following configuration:

<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 Windows sdk and you have a good trace viewer for these log files. This will help you sort out the errors in the WCF message.

+1
source

The use of cross-platform communication sometimes happens (once it happened to my code) that the exception created is not a real description of what is happening inside.

One reason for this exception is that the response time is slightly less than the time required to complete the webservice procedure. So try increasing the timeout in your app.config.

If this does not work, there may be two possible problems in your case.

  • If SSL is used, there is a problem with the validity of the SSL certificate.
  • There are some invalid characters used in XML, for example, your platform does not support Unicode characters, and an invalid character is used in XML.

But I hope that only increasing the timeout will fix this.

+1
source

I got a similar error, and the reason was an exception to XML serialization. Basically, if xmlserializer tries to read some property, and the get method throws an exception because the database connection is already closed or some resources are unavailable.

Have you tried to log exceptions in the error event inside global.asax?

Sometimes, if global.asax does not raise an error event, then there is only a way to register an error through the response filter. You can add a custom response filter to the web.config file, in which you can analyze how XML was correctly serialized and where it might fail.

http://msdn.microsoft.com/en-us/library/aa479332.aspx

http://www.raboof.com/projects/elmah/

0
source

Intermediate connection "An existing connection was forcibly closed by the remote host" from one destination sounds like a network problem for me.

Try to get the logs from the server you are trying to access and from the involved firewalls in both places. You can run Fiddler or NetMon / WireShark / Ethereal for further diagnosis.

0
source

The connection closes under any circumstances. Make sure that the timeout is replete with the server and the client, make sure that there is no recursion in the data you return. Circular link. Serialization is important in this case, because when it is returned, the thing is serialized.

Make a WCF tracer and check the answer. Any error on the server will close the connection. If the server requires a username, make sure they are correct. Take care of the SSL error. use the WCF client to verify the service.

0
source

It may be a shot in the dark, but here is my theory:

The first error occurs on the side of the web service with an exception failure, maybe some invalid data is passed to the service? This can lead to an error associated with malformed XML. I would do some test cases to find out what data is being passed to the service and what causes the problem.

The second error I saw earlier is, in a specific case, regarding the exception of the web service that was selected, and the catch attempt wrapped in a using statement for the service. This combination of logic caused an early exit that was not cleared.

0
source

try checking the existing protocols in your latest company and compare them with your current company, I mean TCP / Ip, ...

0
source

Check the configuration of the application pool utility in IIS. I saw this error, for example, when the "Private memory limit" is set to (say, 100 MB), and then the w3wp process exceeds this limit, which will lead to reuse of the application pool.

This is usually not a problem, as all existing connections are given time to complete, and new connections will be handled by the newly created application pool.

If all connections are not closed within the shutdown time limit (usually 90 seconds), then they are killed by IIS, and the client may raise the message "An existing connection was forcibly closed."

0
source

I'm not sure if this applies to a particular situation in the OP, but it can help others who are coming here now. One potential reason for this exception is inconsistent security protocols. If the server you are calling to requires TLS 1.2 and you are using an older version of ASP.net (<= Version 4.0), you will use the old security protocol to make your calls if you do not 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 immediately 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 
0
source

Source: https://habr.com/ru/post/907508/


All Articles