views:

95

answers:

2

I currently have a WCF Service Library which will be started through a Console Application acting as ServiceHost. The ServiceHost starts the service and then waits with Console.ReadLine() for the "quit" command. If i do "Console.WriteLine();" in the service this will be printed to the ServiceHosts Console of course. The Service prints some information when the clients connect for example.

Is it possible to have the ServiceHost converted to a real Windows Service (to start up when the machine boots without console window) and attach or detach a command prompt (cmd.exe) or another Console Application to it when needed? For example if I want so see which clients connect from now on?

Thanks in advance!

EDIT: I really woudln't like to write and read a LogFile.

+1  A: 

Only if you run on an old operating system, XP is the last one that allows a service to interact with the desktop. You'll need to write a separate app that can run on the user's desktop. Talk to the service through, well, WCF. Or a named pipe or socket.

Hans Passant
The service would run on a Windows 2003 R2 Server. But I found the option to interact with the Desktop also if I go to Services -> Properties -> LogOn in Windows 7.
MemphiZ
Hmya, sux when they don't get this stuff done. Google "session 0 isolation" to hear it from somebody else.
Hans Passant
Ah.. I didn't know that. Could you give me an example how you would to this for Win2k3 R2?
MemphiZ
You won't have this problem on 2003, it has the XP core. You'll need the other approach on 2008.
Hans Passant
A: 

You would be far better off exposing the properties and methods you wish to access on the WCF Service and then creating a console or desktop application that allowed you to access the properties via the WCF service. As you are not limited to a single End Point or interface you could easily implement some form of authentication and use netTcp binding between applications.

Lloyd
Looks like I have to do it this way to be able to install and manage the service on all Windows versions.. Thanks!
MemphiZ