473,772 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

windows service problem

14 New Member
i have a problem when i try to run my windows service ..which is "Error 1053: The service did not respond to the start or control request in a timely fashion"

>after this i cannot anything with the service and have to restart the computer inorder for the service to be deleted.

>1) my service program is basically a client tht is listening on a port to a request from a server and establishing a new connection.

2) reading and extracting the zip file...deserial izing the objects and parameters of the function in the zip file sent

3)invoking the method using the object sent...and sending back a zipped result archive....

the code for my service is as follows...

using System;
using System.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Diagnost ics;
using System.ServiceP rocess;
using System.Text;
using System.IO;

using ServerApp;

using mytestservice.r eference1;
using ICSharpCode.Sha rpZipLib.Zip;
namespace mytestservice
{
public partial class Service1 : ServiceBase
{


protected override void OnStart(string[] args)
{

ServerProgram ts = new ServerProgram() ;
ts.registre();



}

protected override void OnStop()
{

}
}
}

the function registre and class ServerProgram are defined in a separate c#code file within the project which is......

using System;
using System.Collecti ons.Generic;
using System.Text;

using System.Diagnost ics;
using System.Reflecti on;
using System.Runtime. Serialization.F ormatters.Binar y;

using System.IO;
using System.Net;
using System.Net.Sock ets;

using ICSharpCode.Sha rpZipLib.Zip;
//using NSRemoteExecuto rTestObject;

namespace ServerApp
{


class ServerProgram
{



private const string SERIALIZED_OBJE CT_FILE_NAME = "SerializedObje ct.tlp";
private const string SERIALIZED_FUNC TION_PARAMETERS _FILE_NAME = "FunctionParame ters.tlp";

public void registre()
{
do
{
try
{
// Read the callback details to establish a new socket connection
//Console.WriteLi ne("hello");
string callbackMachine Name;
int callbackPortNum ber;
TcpListener listener = new TcpListener(440 0);
listener.Start( );
using (Socket serverSocket = listener.Accept Socket())
{
using (StreamReader callbackDetails Reader = new StreamReader(ne w NetworkStream(s erverSocket)))
{
// Read the machine name to which to send the result
callbackMachine Name = callbackDetails Reader.ReadLine ();

// Read the callback port number
callbackPortNum ber = Int32.Parse(cal lbackDetailsRea der.ReadLine()) ;
}
}
listener.Stop() ;

// Open a new connection on the port specified
char[] buffer = null;
string functionName;
StreamReader reader;
StreamWriter writer;
using (TcpClient connectionToRem oteProcessor = new TcpClient(callb ackMachineName, callbackPortNum ber))
{
reader = new StreamReader(co nnectionToRemot eProcessor.GetS tream());
//using (StreamReader reader = new StreamReader(co nnectionToRemot eProcessor.GetS tream()))
//{
// Read the function name to be invoked
functionName = String.Empty;
functionName = reader.ReadLine ();
Console.WriteLi ne("Function name : {0}", functionName);

// Read the size of the incoming file
int fileSize = Int32.Parse(rea der.ReadLine()) ;
Console.WriteLi ne("Filesize : {0}", fileSize);

// Read the entire file
buffer = new char[fileSize];
reader.Read(buf fer, 0, fileSize);
Console.WriteLi ne("File read");
//}

// Save the file to disk
string zipFileName = String.Format(" {0}.zip", DateTime.Now.Ti cks);
FileStream zipFileStream = File.Open(zipFi leName, FileMode.Create );
foreach (char c in buffer)
zipFileStream.W riteByte((byte) c);
zipFileStream.C lose();
Console.WriteLi ne("Zip file saved");

// Extract the contents
string currentExecutin gDirectory = Directory.GetPa rent(Assembly.G etExecutingAsse mbly().Location ).ToString();
FastZip fastZip = new FastZip();
fastZip.Extract Zip(zipFileName , currentExecutin gDirectory, "");
Console.WriteLi ne("Zip file extracted");

// Create a new binary formatter
BinaryFormatter bf = new BinaryFormatter ();

// Deserialize the invoking object
object invokingObject;
using (FileStream invokingObjectF ileStream = File.OpenRead(S erverProgram.SE RIALIZED_OBJECT _FILE_NAME))
{
invokingObject = bf.Deserialize( invokingObjectF ileStream);
}
Console.WriteLi ne("Object deserialized");

// Deserialize the parameters
Console.Write(" Parameters : ");
int numberOfParamet ers = Directory.GetFi les(currentExec utingDirectory, String.Format(" *_{0}", ServerProgram.S ERIALIZED_FUNCT ION_PARAMETERS_ FILE_NAME)).Len gth;
object[] parameters = new object[numberOfParamet ers];
for (int index = 0; index < numberOfParamet ers; ++index)
{
using (FileStream parametersFileS tream = File.OpenRead(S tring.Format("{ 0}_{1}", index, ServerProgram.S ERIALIZED_FUNCT ION_PARAMETERS_ FILE_NAME)))
{
parameters[index] = bf.Deserialize( parametersFileS tream);
Console.Write(" {0},", parameters[index]);
}
}
Console.WriteLi ne("\nParameter s deserialized");

// Invoke the method on the object
object result = invokingObject. GetType().Invok eMember(functio nName, BindingFlags.In vokeMethod, null, invokingObject, parameters);
Console.WriteLi ne("Method invoked: Result = {0}", result);

// Serialize the result
using (FileStream resultFileStrea m = File.Create("Re sultObject.tlp" ))
{
bf.Serialize(re sultFileStream, result);
}
Console.WriteLi ne("Result serialized");

// Compress the file
FastZip compressResult = new FastZip();
string resultZipFileNa me = String.Format(" Result_{0}", zipFileName);
compressResult. CreateZip(resul tZipFileName, currentExecutin gDirectory, false, "ResultObject.t lp");
Console.WriteLi ne("Compressed result");

// Send the file back to the requesting machine
byte[] writeBuffer;
using (FileStream zipFileReader = File.OpenRead(r esultZipFileNam e))
{
writeBuffer = new byte[zipFileReader.L ength];
zipFileReader.R ead(writeBuffer , 0, (int)zipFileRea der.Length);
}

char[] transmitBuffer = new char[writeBuffer.Len gth];
for (int index = 0; index < writeBuffer.Len gth; ++index)
transmitBuffer[index] = (char)(writeBuf fer[index]);

// Read the zip file containing serialized result object into memory
using (writer = new StreamWriter(co nnectionToRemot eProcessor.GetS tream()))
{
// Send the filesize of the entire package across
//writer.Write(wr iteBuffer.Lengt h);
//writer.Flush();
//Console.WriteLi ne("Sent filesize : {0}", writeBuffer.Len gth);

// Send the zip file containing the DLL's and serialized objects
writer.Write(tr ansmitBuffer);
writer.Flush();
Console.WriteLi ne("Sent result archive");
}
}
Console.WriteLi ne("Success!\n\ n");
}
catch (Exception exc)
{
EventLog.WriteE ntry("Paralleli zer", String.Format(" {0}\n{1}\n{2}\n {3}", exc.Message, exc.Data, exc.GetBaseExce ption().InnerEx ception, exc.StackTrace) , EventLogEntryTy pe.Error);
Console.WriteLi ne(exc.Message + "@" + exc.StackTrace) ;
Console.ReadKey ();
}
}

while (1 != 0);

}

}
}
Apr 2 '08 #1
0 1576

Sign in to post your reply or Sign up for a free account.

Similar topics

1
3288
by: bob | last post by:
I have created a simple Windows service in VB.Net which installs fine using InstallUtil.exe to install it to, for example "c:\test", or "c:\Windows\YellowBanana", but if I install it to "c:\Program Files\Test" it installs ok but will not start (no useful error message is given other than the usual annoying suggestion about having sufficient privileges). The problem only seems to happen with spaces, not long filenames. I have found a...
2
2581
by: epaetz | last post by:
I'm getting Not associated with a trusted SQL Server connection errors on a .Net windows service I wrote, when it's running on my application server. It's not a problem with mixed mode security. I'm set for mixed mode and I've been running the service on the app server for over a month with no problem. My database is running on a second server and both are under the same domain. The problem has occurred twice over the last two months.
2
2941
by: Neslihan ERDEM | last post by:
Every body Hi first of all I say Why do I need Windows Service / Every Day I create XML file . I writed a XML web service And .I join this servis Windows service. I create Windows Service that I call method XML Web Service . My Problem I generate Windows Service but I want this service always run . But I dont make it
4
9025
by: Kris | last post by:
I have a Windows Service in C# talking to a serial port and using Remoting. It also uses several COM objects. On customer's computer the service will occassionally hang somewhere - the service still shows on a Task Manager list. In Services it says it is still running. However there is no way to stop it other than by rebooting the whole computer. No exception (including non-CLS) is ever generated. I added a separate System.Timers.Timer...
0
3940
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server - Select from two specific services - Check the status of the server
10
3490
by: Ger | last post by:
I am having problems using VB.Net's Management base object on a machine hosting Windows Server 2003. I am trying to set file permissions from a Windows Service. These files may be loacted on a local machine or somewhere on the network. I use the Management Base Object to set these permissions which works perfectly when the windows service is running on an XP machine. However, when the service is running on a Windows Server 2003 machine I...
3
3497
by: Evan Camilleri | last post by:
I have a problem for a Windows Service to login on an SQL server (different machine) - neither Windows Authentication nor SQL Authentication worked. LOGIN FAILED FOR USER sa (for example). If SQL Server is on the same PC of the Windows Service the connection works OK. The same code works in a Windows Form using same user and authentication methods to the SQL Server on a different machine.
0
2229
by: Charles Leonard | last post by:
I am having yet another issue with Windows Server 2003. This time, the web service (a file import web service) appears to run except for one odd message: "ActiveX component can't create object". There are no other statements to indicate what object cannot be created. Otherwise, everything on the test Windows Server 2003 works fine—all import data updates correctly. Unfortunately, my normal development environment is not Windows...
2
6900
by: deko | last post by:
When to use a privileged user thread rather than a windows service? That's the question raised in a previous post . It was suggested that if the service needs to interact with a WinForms app (which is the UI used to adjust the actions taken by, and the schedule of the service), then a privileged user thread should be used in the UI - no service required. But... "A windows service enables the creation of long-running executable
1
1956
by: Mahesh Devjibhai Dhola | last post by:
Hi, Scenario: The webservice was developed on windows 2000 Pro and deployed previously on windows XP pro for testing. We have tested for many days. The client for that service was 30+ and accessing the webservice each min. It was working 100% fine. Problem: But now in actual deployment, we have deployed webservice in Win Server 2003 and we have used all the default configurations. Now the clients are accessing that service the same way...
0
10264
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10106
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10039
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6716
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5484
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4009
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3610
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2851
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.