I create a service like this :
private SocketDataRepository socketRepository = new SocketDataRepository();
SerivceIPconfigRepository serivceIPconfigRepository=new SerivceIPconfigRepository();
public AsyncCallback pfnWorkerCallBack;
private Socket m_mainSocket;
private Socket[] m_workerSocket = new Socket[25];
private int m_clientCount = 0;
private string ipaddress;
protected override void OnStart(string[] args)
{
ServiceIpConfig serviceIpConfig = serivceIPconfigRepository.GetAll().First();
DrawMapPersian();
ipaddress = serviceIpConfig.IncomingIP;
// Check the port value
string portStr = serviceIpConfig.IncomingPort;
int port = System.Convert.ToInt32(portStr);
// Create the listening socket...
m_mainSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream,
ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, port);
// Bind to local IP Address...
m_mainSocket.Bind(ipLocal);
// Start listening...
m_mainSocket.Listen(4);
// Create the call back for any client connections...
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);
}
protected override void OnContinue()
{
base.OnContinue();
}
protected override void OnStop()
{
}
As you can see my service listens to a port for incoming data .I also add an installer for my service as you can see here :
[RunInstaller(true)]
public class MyWindowsServiceInstaller : Installer
{
public MyWindowsServiceInstaller()
{
var processInstaller = new ServiceProcessInstaller();
var serviceInstaller = new ServiceInstaller();
//set the privileges
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.DisplayName = "My Service";
serviceInstaller.StartType = ServiceStartMode.Manual;
//must be the same as what was set in Program's constructor
serviceInstaller.ServiceName = "My Service";
this.Installers.Add(processInstaller);
this.Installers.Add(serviceInstaller);
}
}
I install my service using installutil.exe
.everything works fine and my service installed and i can see it in list of services .but when i try to start that i got this error :
I check the log event and my error is this:
Provider
[ Name] My Service
- EventID 0
[ Qualifiers] 0
Level 2
Task 0
Keywords 0x80000000000000
- TimeCreated
[ SystemTime] 2014-08-17T15:38:21.000000000Z
EventRecordID 7526
Channel Application
Computer ehsan-PC
Security
- EventData
Service cannot be started. The service process could not connect to the service controller
Where is my problem ?