473,385 Members | 1,930 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

windows service problem

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...deserializing 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.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Text;
using System.IO;

using ServerApp;

using mytestservice.reference1;
using ICSharpCode.SharpZipLib.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.Collections.Generic;
using System.Text;

using System.Diagnostics;
using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary;

using System.IO;
using System.Net;
using System.Net.Sockets;

using ICSharpCode.SharpZipLib.Zip;
//using NSRemoteExecutorTestObject;

namespace ServerApp
{


class ServerProgram
{



private const string SERIALIZED_OBJECT_FILE_NAME = "SerializedObject.tlp";
private const string SERIALIZED_FUNCTION_PARAMETERS_FILE_NAME = "FunctionParameters.tlp";

public void registre()
{
do
{
try
{
// Read the callback details to establish a new socket connection
//Console.WriteLine("hello");
string callbackMachineName;
int callbackPortNumber;
TcpListener listener = new TcpListener(4400);
listener.Start();
using (Socket serverSocket = listener.AcceptSocket())
{
using (StreamReader callbackDetailsReader = new StreamReader(new NetworkStream(serverSocket)))
{
// Read the machine name to which to send the result
callbackMachineName = callbackDetailsReader.ReadLine();

// Read the callback port number
callbackPortNumber = Int32.Parse(callbackDetailsReader.ReadLine());
}
}
listener.Stop();

// Open a new connection on the port specified
char[] buffer = null;
string functionName;
StreamReader reader;
StreamWriter writer;
using (TcpClient connectionToRemoteProcessor = new TcpClient(callbackMachineName, callbackPortNumber))
{
reader = new StreamReader(connectionToRemoteProcessor.GetStream ());
//using (StreamReader reader = new StreamReader(connectionToRemoteProcessor.GetStream ()))
//{
// Read the function name to be invoked
functionName = String.Empty;
functionName = reader.ReadLine();
Console.WriteLine("Function name : {0}", functionName);

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

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

// Save the file to disk
string zipFileName = String.Format("{0}.zip", DateTime.Now.Ticks);
FileStream zipFileStream = File.Open(zipFileName, FileMode.Create);
foreach (char c in buffer)
zipFileStream.WriteByte((byte)c);
zipFileStream.Close();
Console.WriteLine("Zip file saved");

// Extract the contents
string currentExecutingDirectory = Directory.GetParent(Assembly.GetExecutingAssembly( ).Location).ToString();
FastZip fastZip = new FastZip();
fastZip.ExtractZip(zipFileName, currentExecutingDirectory, "");
Console.WriteLine("Zip file extracted");

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

// Deserialize the invoking object
object invokingObject;
using (FileStream invokingObjectFileStream = File.OpenRead(ServerProgram.SERIALIZED_OBJECT_FILE _NAME))
{
invokingObject = bf.Deserialize(invokingObjectFileStream);
}
Console.WriteLine("Object deserialized");

// Deserialize the parameters
Console.Write("Parameters : ");
int numberOfParameters = Directory.GetFiles(currentExecutingDirectory, String.Format("*_{0}", ServerProgram.SERIALIZED_FUNCTION_PARAMETERS_FILE_ NAME)).Length;
object[] parameters = new object[numberOfParameters];
for (int index = 0; index < numberOfParameters; ++index)
{
using (FileStream parametersFileStream = File.OpenRead(String.Format("{0}_{1}", index, ServerProgram.SERIALIZED_FUNCTION_PARAMETERS_FILE_ NAME)))
{
parameters[index] = bf.Deserialize(parametersFileStream);
Console.Write("{0},", parameters[index]);
}
}
Console.WriteLine("\nParameters deserialized");

// Invoke the method on the object
object result = invokingObject.GetType().InvokeMember(functionName , BindingFlags.InvokeMethod, null, invokingObject, parameters);
Console.WriteLine("Method invoked: Result = {0}", result);

// Serialize the result
using (FileStream resultFileStream = File.Create("ResultObject.tlp"))
{
bf.Serialize(resultFileStream, result);
}
Console.WriteLine("Result serialized");

// Compress the file
FastZip compressResult = new FastZip();
string resultZipFileName = String.Format("Result_{0}", zipFileName);
compressResult.CreateZip(resultZipFileName, currentExecutingDirectory, false, "ResultObject.tlp");
Console.WriteLine("Compressed result");

// Send the file back to the requesting machine
byte[] writeBuffer;
using (FileStream zipFileReader = File.OpenRead(resultZipFileName))
{
writeBuffer = new byte[zipFileReader.Length];
zipFileReader.Read(writeBuffer, 0, (int)zipFileReader.Length);
}

char[] transmitBuffer = new char[writeBuffer.Length];
for (int index = 0; index < writeBuffer.Length; ++index)
transmitBuffer[index] = (char)(writeBuffer[index]);

// Read the zip file containing serialized result object into memory
using (writer = new StreamWriter(connectionToRemoteProcessor.GetStream ()))
{
// Send the filesize of the entire package across
//writer.Write(writeBuffer.Length);
//writer.Flush();
//Console.WriteLine("Sent filesize : {0}", writeBuffer.Length);

// Send the zip file containing the DLL's and serialized objects
writer.Write(transmitBuffer);
writer.Flush();
Console.WriteLine("Sent result archive");
}
}
Console.WriteLine("Success!\n\n");
}
catch (Exception exc)
{
EventLog.WriteEntry("Parallelizer", String.Format("{0}\n{1}\n{2}\n{3}", exc.Message, exc.Data, exc.GetBaseException().InnerException, exc.StackTrace), EventLogEntryType.Error);
Console.WriteLine(exc.Message + "@" + exc.StackTrace);
Console.ReadKey();
}
}

while (1 != 0);

}

}
}
Apr 2 '08 #1
0 1532

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

Similar topics

1
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...
2
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...
2
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...
4
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...
0
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 -...
10
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...
3
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...
0
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". ...
2
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...

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.