V
vinoth
Hi,
I have created WindowsService Project.In that Project OnStart Method
i have written the following Code. In this code the Server is waiting
for the connection from client. When the Client connects to the Server,
the server will process and send result to the client.(This is Client
Server Application. The Server side Code is implementd in th OnStart
method Of Windows Service).
When i tried the Client Server Application in Console Application it's
working fine. But When i make the Server side Code in to Windows
Service Application(OnStart method), i can able to create Service
also.(I given the Service Automatic in the Properyt Window and Account
is LocalSystem). But when i try to start the Service its Giving the
Following Error.
Error:-
Could not Start the Listener Service on Local Computer.
"Error 1053: The service did not respond to the start or control
request in a timely fashion"
How should i solve this issue. If anybody knows the solution please let
me know.
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Service Started...");
try
{
Int32 port = 56789;
IPAddress localAddr = IPAddress.Parse("192.168.1.10");
TcpListener server = new TcpListener(localAddr, port);
server.Start();
Socket tcpSocket = server.AcceptSocket();
if(tcpSocket.Connected)
{
EventLog.WriteEntry("Connected... " + DateTime.Now);
NetworkStream stream = new NetworkStream(tcpSocket);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
ArrayList clientReqAL = null;
byte[] buffer = new byte[1024];
int i;
MemoryStream mStream = new MemoryStream();
while((i = stream.Read(buffer,0,buffer.Length)) != 0)
{
mStream.Write(buffer,0,i);
if(!stream.DataAvailable)
break;
}
mStream.Seek(0, SeekOrigin.Begin);
clientReqAL = (ArrayList)xs.Deserialize(mStream);
string methodName = (string)clientReqAL[0];
clientReqAL.RemoveAt(0);
object wrapperInst = GetWrapperInstance(methodName);
object[] Parameters = new object[2];
Parameters[0] = methodName;
Parameters[1] = clientReqAL;
if(wrapperInst!=null)
{
object result =
wrapperInst.GetType().InvokeMember("CallMethod",BindingFlags.InvokeMethod,null,wrapperInst,Parameters);
if(stream.CanWrite)
{
byte[] sendByteData =
System.Text.Encoding.Default.GetBytes(result.ToString());
stream.Write(sendByteData,0,sendByteData.Length);
}
stream.Close();
}
}
EventLog.WriteEntry("Before Close "+DateTime.Now);
tcpSocket.Close();
}
catch (Exception e)
{
EventLog.WriteEntry(e.Message);
}
}
Thanks,
Vinoth
I have created WindowsService Project.In that Project OnStart Method
i have written the following Code. In this code the Server is waiting
for the connection from client. When the Client connects to the Server,
the server will process and send result to the client.(This is Client
Server Application. The Server side Code is implementd in th OnStart
method Of Windows Service).
When i tried the Client Server Application in Console Application it's
working fine. But When i make the Server side Code in to Windows
Service Application(OnStart method), i can able to create Service
also.(I given the Service Automatic in the Properyt Window and Account
is LocalSystem). But when i try to start the Service its Giving the
Following Error.
Error:-
Could not Start the Listener Service on Local Computer.
"Error 1053: The service did not respond to the start or control
request in a timely fashion"
How should i solve this issue. If anybody knows the solution please let
me know.
protected override void OnStart(string[] args)
{
EventLog.WriteEntry("Service Started...");
try
{
Int32 port = 56789;
IPAddress localAddr = IPAddress.Parse("192.168.1.10");
TcpListener server = new TcpListener(localAddr, port);
server.Start();
Socket tcpSocket = server.AcceptSocket();
if(tcpSocket.Connected)
{
EventLog.WriteEntry("Connected... " + DateTime.Now);
NetworkStream stream = new NetworkStream(tcpSocket);
XmlSerializer xs = new XmlSerializer(typeof(ArrayList));
ArrayList clientReqAL = null;
byte[] buffer = new byte[1024];
int i;
MemoryStream mStream = new MemoryStream();
while((i = stream.Read(buffer,0,buffer.Length)) != 0)
{
mStream.Write(buffer,0,i);
if(!stream.DataAvailable)
break;
}
mStream.Seek(0, SeekOrigin.Begin);
clientReqAL = (ArrayList)xs.Deserialize(mStream);
string methodName = (string)clientReqAL[0];
clientReqAL.RemoveAt(0);
object wrapperInst = GetWrapperInstance(methodName);
object[] Parameters = new object[2];
Parameters[0] = methodName;
Parameters[1] = clientReqAL;
if(wrapperInst!=null)
{
object result =
wrapperInst.GetType().InvokeMember("CallMethod",BindingFlags.InvokeMethod,null,wrapperInst,Parameters);
if(stream.CanWrite)
{
byte[] sendByteData =
System.Text.Encoding.Default.GetBytes(result.ToString());
stream.Write(sendByteData,0,sendByteData.Length);
}
stream.Close();
}
}
EventLog.WriteEntry("Before Close "+DateTime.Now);
tcpSocket.Close();
}
catch (Exception e)
{
EventLog.WriteEntry(e.Message);
}
}
Thanks,
Vinoth