I searched foe the solution but could not get it. Here is the code for windows service.
 protected override void OnStart(string[] args)
    {
        Debugger.Launch();
        try {
           AsynchronousSocketListener.StartListening();
            // Log an event to indicate successful start.
            EventLog.WriteEntry("Successful start.", EventLogEntryType.Information);
        }
        catch(Exception ex)
        {
            // Log the exception.
            EventLog.WriteEntry(ex.Message, EventLogEntryType.Error);
        }
    }
Here is the class AsynchronousSocketListner
 static string constr = "Integrated Security=SSPI;Persist Security Info=False;Data Source=WIN-OTVR1M4I567;Initial Catalog=CresijCam";
    //string test = constr;
    // Thread signal.  
    public static  ManualResetEvent allDone = new ManualResetEvent(false);
    private  AsynchronousSocketListener()
    {
    }
    public static void StartListening()
    {
        // Establish the local endpoint for the socket.  
        // The DNS name of the computer  
        IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, 1200);
        // Create a TCP/IP socket.  
        Socket listener = new Socket(AddressFamily.InterNetwork,
            SocketType.Stream, ProtocolType.Tcp);
        // Bind the socket to the local endpoint and listen for incoming connections.  
        try
        {
            listener.Bind(localEndPoint);
            listener.Listen(200);
            while (true)
            {
                // Set the event to nonsignaled state.  
                 allDone.Reset();
                // Start an asynchronous socket to listen for connections.  
                listener.BeginAccept(
                    new AsyncCallback(AcceptCallback),
                    listener);
                // Wait until a connection is made before continuing.  
                 allDone.WaitOne();
            }
        }
        catch (Exception e)
        {
            string me = e.Message;
        }
    }
I am getting different Error messages everytime:
A timeout (30000 milliseconds) was reached while waiting for a transaction response from the TCPService service.
Service cannot be started. The service process could not connect to the service controller
I dont know from where is the error that I am getting is coming. I know one thing that service is not run yet. and It is in this method startListening(). I debugged using Debugger.launch(). But I am not getting to a specific line . I also think this is related to TCP somewhere but nothing for sure.
The same code is in working state for console Project. I dont know what other code to put here. But please let me know if needed further detail.