简体   繁体   中英

Restarts c# windows service on a url call

I have ac# application which runs as a windows service. This application uses open source tiny http server for URL communications. There is a flext application developed to update and select the data from sqlite database via c# application using get/post methods.

I have a url called https:/domainname:portnumber/folder/tree/200 which reads data from database with the help of ac# service and returns a huge amount of data in xml form to the client.

Some times when this url gets called totral c# windows service is getting restarted. And then needs to refresh the flext application to start it again. The server firewall where the windows service is installed is turned off and the machine is also reachable.

When I checked log I found after this url call, the server restarts. Also, when I checked the traffic in fiddler I got 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 for calling 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;
    }
}

To execute the query from sqlite database the code below is used

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();
    }          
}

Whats the size of the return string? You could write it to a file to verify the length of the return string.

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

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

The Service may crash if you have not handled the exception.

In that service, that is sending a big bunch of text over http; when writing to the reponse add response.BufferOutput = false; at the beginning of the method and call Flush after every some writes.

Note: I am not sure if this works in your embedded http server. But this works for IIS.

It looks as if your SQL code is not catching exceptions... At least not immediately within the method. It stands to reason that if an exception were thrown, the service would crash due to the unhandled exception. Try hooking into the AppDomain.UnhandledException event and printing any caught exceptions to a file, log source, etc. This will allow you to determine if SQL exceptions (read timeouts, etc.) are causing the crash.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM