Restarts C # windows service when calling URL

I have a C # application that runs as a windows service. This application uses a tiny open source HTTP server to communicate by URL. There is a flext application designed to update and select data from a sqlite database using a C # application using get / post methods.

I have a url https: / domainname: portnumber / folder / tree / 200 that reads data from a database using a C # service and returns a huge amount of data in xml form to the client.

In some cases, when this url gets called by totral C #, the windows service restarts. And then you need to update the flext application to start it again. The firewall of the server on which the Windows service is installed is disabled, and the machine is also available.

When I checked the log I found after this URL call, the server will reboot. Also, when I checked the traffic in the violinist, I received the error below:

HTTP/1.1 502 Fiddler - Connection Failed Content-Type: text/html; charset=UTF-8 Connection: close Timestamp: 10:18:52.685 [Fiddler] The socket connection to (domainname) failed. <br />ErrorCode: 10061. 

The code used to call this folder / tree is below

 public string Tree() { try { string langstr = ""; if (Request.QueryString["lang"] != null && !string.IsNullOrEmpty(Request.QueryString["lang"].Value)) { langstr = Request.QueryString["lang"].Value.ToString(); } else { ThingzDatabase db = SessionDatabase; langstr = db.DefaultLanguage; db = null; } folderTree = new FolderTree(Convert.ToInt32(Id), true, SessionDatabase, langstr); XmlDocument doc = folderTree.XML; Response.ContentType = ContentType.Xml; langstr = null; folderTree.db2 = null; folderTree = null; //GC.Collect(); return doc.InnerXml; } catch (Exception e) { TouchServer.Log(Logger.MessageType.Error, 1, e.ToString()); return "Get folder tree failed, reason:" + e.Message; } } 

The following code is used to execute a query from the sqlite database

 public SQLiteDataReader ExecuteSQL(String sqlExpr) { if (conn.State != ConnectionState.Open Open(DataFile); using (SQLiteCommand cmd = conn.CreateCommand()) { cmd.CommandText = sqlExpr + ";PRAGMA read_uncommitted = 1;"; cmd.CommandType = CommandType.Text; return cmd.ExecuteReader(); } } 
+4
source share
3 answers

What is the size of the returned string? You can write it to a file to check the length of the returned string.

There may be problems with the web service if the length exceeds a certain limit.

The following link discusses a similar issue. http://social.msdn.microsoft.com/forums/en-US/wcf/thread/58e420e9-43a3-4119-b541-d18158038e36/

A service may crash if you do not handle the exception.

+1
source

In this service, which sends a large pile of text via http; when writing to the response, add response.BufferOutput = false; at the beginning of the method and call Flush after each entry.

Note. I'm not sure if this works on the embedded HTTP server. But it works for IIS.

0
source

It seems that your SQL code does not catch the exception ... At least not immediately within the framework of the method. Of course, if an exception were thrown, the service would crash due to an unhandled exception. Try connecting to the AppDomain.UnhandledException event and print all detected exceptions in the file, log source, etc. This will allow you to determine if SQL exceptions (read timeouts, etc.) are causing the failure.

0
source

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


All Articles