Tag Archive | Services

Host a service in a managed application

I think I have mentioned it before (if I haven’t, I’ll surely do now) that WCF isn’t about web services. It’s about services, as a whole. There are no restrictions on where and how you’d like to host your service. Given this, I’ll show three easy and quick ways in this post to host your WCF services in managed applications:

  • Host with an application having a UI
  • Host with a Windows Service
  • Host with the WCF-provided host

The first two options are essentially the same, the only difference is that Windows Services don’t have a user interface, and they have their own ways of installation and running. But let’s treat them as separate objectives.

We’ll use the simplest form of applications, the Console Application to self-host our WCF service. So if you’re ready (created a console app), add the necessary code files to it (the service class, and the service contract interface, plus an app.config). I’m sure you’ll be able to write a simple service by now, and the whole purpose of this post is to show you how to host your written services, instead of how to write them, so I’ll omit the creation of a service. Let’s assume you’ve a service called MyService, with a contract interface IMyService. Given this, you’d host your service by using the ServiceHost class:

Read More…

Implement, Install and Control a Service

A Windows Service is a process without a user interface, that runs constantly in the background in its own session. This said, hit CTRL+ALT+DEL, select the Task Manager, then the Services pane, and hit the Services button. First ensure that you are using Windows, then that you have administrative rights. What you will see are the Windows Services. Friend with them, they are not malevolent.

Now that we know what is exactly a Windows Service, let’s try to create one. There are two ways to do so, the easy one with Visual Studio pregenerating all of the exciting code – and the cool way to write it by hand. You can choose any one of them, the result will be the same.

Unfortunately a service cannot be run by itself (as long as it isn’t a WCF service, but for this objective, it isn’t), so you cannot debug your services and test them with Visual Studio, which is definitely a bad thing.

Read More…