|
-
June 28th, 2009, 02:12 AM
#1
WCF and Window service
I need to create a window service and i want to create it using the latest c# technology.
i'm just reading about WCF and i see no article that explain the connection between WCF and Windows service (only WCF and Web Services).
Can i write Window service, in WCF ?
-
June 28th, 2009, 05:09 AM
#2
Re: WCF and Window service
-
June 28th, 2009, 02:40 PM
#3
Re: WCF and Window service
They are different things.
Web Service - essentially and api (i.e. class and methods) exposed through the internet.
Windows Service - an long running app that automatically starts at system startup and provides non-UI type functionality.
WCF Service - in a nutshell WCF is the newer way to create web services over ASMX.
One of the differences between Web Service in ASP.Net and WCF (asmx), is that the older web service had to be hosted in IIS. With WCF you have several options for hosting: IIS (like the older ws), a console app, a Windows app, or a Windows service.
Decoupling from IIS has several benefits because, while you may want to host a web service, you may want to limit the security footprint and not have IIS running.
Since WCF services can now be hosted in windows apps, WCF can be used as interprocess communication between two applications.
Windows Services make an ideal WCF hosting platform because it can run without requiring a user logon. This type of arrangement solves the classic problem of notifying clients from a Windows service (remember Windows Services in this day and age shouldn't interact with the desktop). So say I have a monitoring app that monitors some process and if a failure occurs needs to send a notification to users logged on to a machine. The design would be a two component design where the monitoring functionality would be contained within the windows service. The UI component (tray notification) would be started when a user logs on and WCF web service would be used to communicate between the windows service and each UI component. Along with providing the monitoring functionality, the Windows Service would also host the WCF service that communicates with the UI components. Typically a duplex interface would be used so the Window Service hosting the WCF would fire notification events that the UI component would respond to.
I mentioned that WCF services can be hosted in a console application. In my opinion, this is only useful for test applications but not desireable for production. Sure you can do it, but it's pretty fragile (in that someone can accidently close the console window and take down the WCF service).
WCF offers additional options over the traditional ASMX approach including transport and security options. My recommendation if you are starting to write a web service is to use WCF instead of the older approach.
In my work, I typcially favor hosting WCF inside a Windows Service. I like it so much I have created a generic windows service that hosts any WCF services found within the config file.
-
June 29th, 2009, 02:28 AM
#4
Re: WCF and Window service
WOW! These are professional Answers!
Thats dannystommen and arjay.
Arjay, so if i understand you right, A Window service can't interact with the GUI so i create a WCF web service that the Window service host it.
Do i create the window service in the "usual way"? or there is some kind of new WCF Window service?
Can i use the WCF service as a stand alone web service in the future? or i create a special WCF service for the specific window service hosting?
-
June 29th, 2009, 02:50 AM
#5
Re: WCF and Window service
 Originally Posted by asafaa
Arjay, so if i understand you right, A Window service can't interact with the GUI so i create a WCF web service that the Window service host it.
The fact that the Windows Service doesn't interact with a UI isn't really important for hosting a WCF service. I mentioned an example of this only to show that you can have a Windows service do some work and use a WCF service to communicate with some UI clients.
 Originally Posted by asafaa
Do i create the window service in the "usual way"? or there is some kind of new WCF Window service?
No, it's a standard Windows Service. Inside it, you use the ServiceHost class to host the WCF service.
 Originally Posted by asafaa
Can i use the WCF service as a stand alone web service in the future? or i create a special WCF service for the specific window service hosting?
You create the WCF service as you normally do. Later you can still host it in IIS (or a Windows Service, or a Windows app, etc.).
-
June 29th, 2009, 03:02 AM
#6
Re: WCF and Window service
-
November 1st, 2009, 04:50 PM
#7
Re: WCF and Window service
Arjay's reply we very informative, but I can't clearly figure out a design solution for my problem:
I have a windows forms application which has to do some work when requested by a remote computer on a network.
For example;
a WinForms application, program.exe, is running on computer A.
program.exe has a variable named 'variable1' which needs to be changed on run time.
Note that program.exe has methods, i.e. SetVariable1(int val), which are readily used by its GUI.
The requirements are:
1. On computer B another WinForms application, say programClient.exe, should be able to change variable1 (either by calling SetVariable1 or by any method you would suggest).
2. A web page is hosted on Computer A say webPage1. A browser is viewing webPage1 and it should be able to change variable1 from webPage1.
WCF seems to be the solution for this task according to what Arjay says however as I said in the beginning I am not able to see clearly how WCF can be used in this task.
-
November 1st, 2009, 08:50 PM
#8
Re: WCF and Window service
This shouldn't be too difficult. See my reply in this post, http://www.codeguru.com/forum/showthread.php?t=487121, for an example of using WCF to interact between two instances of a console application.
That code should be a good starting point.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|