Services, C#

S

Sourcerer

I've started my first practice windows service project in C#, and I'm already
stuck.

Let's say I'm trying to make a simple service (and useless, but good for
practice). It is supposed to listen on port which is stored in its configuration
file (say C:\MyService\Config.CFG). After it receives something (anything), then
it is supposed to open a file C:\MyService\File.TXT, read the number that is
written in it, increase it by 1, save it, send it to the application that
originally sent the query, close the file and wait for further queries.

In the above, there are three key moments which prevent me from programming such
a service:
1. How do I make the service listen on any port?
2. What is the event that is raised (or what do I need to do), when some query
actually arrives at that port?
3. How do I make the service send the response to an application which made the
query?

If necessary and if you can, disregard the existing standard communication
protocols, as I will be programming the client side too, so I suppose it doesn't
matter what's the format of my response.

The client, however, is another problem:
How do I make another program (I am programming it) send the query to the port
on which my service is listening, and how does it read the response?

Thanks,
Nikola

--
"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/
 
S

Sourcerer

This isn't a reply, I've only added one more question at the end.

Sourcerer said:
I've started my first practice windows service project in C#, and I'm already
stuck.

Let's say I'm trying to make a simple service (and useless, but good for
practice). It is supposed to listen on port which is stored in its
configuration file (say C:\MyService\Config.CFG). After it receives something
(anything), then it is supposed to open a file C:\MyService\File.TXT, read the
number that is written in it, increase it by 1, save it, send it to the
application that originally sent the query, close the file and wait for
further queries.

In the above, there are three key moments which prevent me from programming
such a service:
1. How do I make the service listen on any port?
2. What is the event that is raised (or what do I need to do), when some query
actually arrives at that port?
3. How do I make the service send the response to an application which made
the query?

If necessary and if you can, disregard the existing standard communication
protocols, as I will be programming the client side too, so I suppose it
doesn't matter what's the format of my response.

The client, however, is another problem:
How do I make another program (I am programming it) send the query to the port
on which my service is listening, and how does it read the response?

While the above still isn't clear, I was using the documentation to create a
service, and put it on my services list. I've followed the tutorial
"Walkthrough: Creating a Windows Service Application in the Component Designer"
to the letter. I've installed the service and it appeared on my available
services list.

However, it failed to start. Event log only contained the following message:

Service cannot be started. The service process could not connect to the service
controller

What am I doing wrong?

--
"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/
 
W

William DePalo [MVP VC++]

Sourcerer said:
I've started my first practice windows service project in C#, and I'm
already stuck.

You may get a response here, but as this is a VC++ group, you are more
likely to find help in one of the C# groups, e.g.:

microsoft.public.dotnet.languages.csharp

or perhaps in one of the platform groups, e.g.:

micosoft.public.dotnet.framework

Regards,
Will

www.ivrforbeginners.com
 
S

Sourcerer

William DePalo said:
You may get a response here, but as this is a VC++ group, you are more likely
to find help in one of the C# groups, e.g.:

microsoft.public.dotnet.languages.csharp

or perhaps in one of the platform groups, e.g.:

micosoft.public.dotnet.framework


Ah, I see. The group name doesn't specify the language and I've seen some C#
questions being answered here, so I thought I'm at the right place.

Thanks for the directions.

Nikola

--
"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/
 
B

Ben Voigt

Sourcerer said:
Ah, I see. The group name doesn't specify the language and I've seen some
C# questions being answered here, so I thought I'm at the right place.

Actually it does, only "C" is such a short name that it might not jump out
at you. (Though people never have trouble figuring out "VB"...)
 
S

Sourcerer

Ben Voigt said:
Actually it does, only "C" is such a short name that it might not jump out at
you. (Though people never have trouble figuring out "VB"...)

Mind you, C is a lot different than C++.
And there is no VC in dotnet as far as I know (only VC++ and VC#).

Since the group name doesn't specify whether it's about VC++ or VC#, I assumed
it's about both. I wasn't at all confused about whether or not it discusses VB
or VJ# or something else.

--
"It is easy in the world to live after the world's opinion; it easy in solitude
to live after our own; but the great man is he who in the midst of the crowd
keeps with perfect sweetness the independence of solitude."
Ralph Waldo Emerson, Self-reliance 1841
http://pinpoint.wordpress.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top