walterhuang
walterhuang

Reputation: 632

How to self-host WCF in Windows Forms without another Windows process

I have a Windows application and want to self-host a WCF in it. This MSDN article walks you through how to self-host WCF in a console. Jason Henderson's article demonstrates how to call the service. But the problem is, I don't want to host my service in another Windows process. I want to host it in my client application. Here is my approach:

  1. Ctrl + F5 to run the service
  2. Add service reference to my client application

Then I can start the service in my client like this

static void Main()
{
    ServiceHost host = new ServiceHost(typeof(MyService));
    host.Open();
    Application.Run(new Form1());
    host.Close();
}

It works. But what is the best way for doing this?

Upvotes: 1

Views: 2745

Answers (1)

devHead
devHead

Reputation: 822

that is exactly what Microsoft recomends:

Hosting in Windows Services http://msdn.microsoft.com/en-us/library/bb332338.aspx

Upvotes: 2

Related Questions