A WCF service can be hosted in IIS, Managed Windows Services, Windows Activation Service (WAS) and Self-hosting. I have already explained how to Host WCF service in IIS and how to host a WCF service in managed Windows Service in my previous post. Let’s learn here how to consume a WCF service hosted in Windows Service in Visual Studio 2010 using console application.
I hope you enjoyed the article. Could you please share the article on your social media? Thank you!
Following few articles might be of your interest -
1) How to self host the WCF service?
2) How to consume WCF service in ASP.net?
3) How to host WCF service in IIS?
4) How to enable WCF tracking and MessageLogging?
To consume the WCF service I am considering an example given in my previous post i.e how to host a WCF service in managed Windows Service. The service will accept a name at console and will return a welcome message like “Welcome to http://www.a1ashiish-csharp.blogspot.in, Mr. Ashish Ramteke”.
Let’s start -
1) Your WCF service must be ready and running windows service. You can check the status of your WCF service using either Service Control Manager or Task Manager. Open Task Manager and goto Services tab to check the status of your service whether it is running or stopped. If it is stopped then right click on the service and then select Start Service.
![]() |
| WCF Service - Task Manager showing the status of WCF Windows Service. |
2) Once your service is started, you can access it by the base address (URL) provided in the configuration file i.e app.config of your WCF service. In this post, I am assuming the base address (URL) of my previous post how to host a WCF service in managed Windows Service i.e “http://localhost:8000/WCFWindowsServiceHosting/Welcome”.
3) Now create a console application that will consume the WCF service.
Let’s name this console consumer application as WCFWindowsServiceConsumeApp.
![]() |
| WCF Service - Creating a consumer console application to consume the WCF Windows Service. |
4) Add your WCF service reference to this consumer application. To add the WCF service reference, right click on project WCFWindowsServiceConsumeApp in Solution Explorer, and select Add Service Reference.
![]() |
| WCF Service - WCF Service - Adding Service Reference to consumer application. |
5) Enter WCF service URL in Address: field and click on Go button. If the service is running then service(s) found at address message appears and your service appears in Services: panel.
![]() |
| WCF Service -Service Reference Window. |
Name the service reference as WCFWindowsServiceReference and click on OK button.
6) The service reference appears in solution explorer.
![]() |
| WCF Service - WCF windows service Reference appearing in Solution Explorer. |
7) Add following lines of code to program.cs file –
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WCFWindoxServiceConsumeApp
{
class Program
{
static void Main(string[] args)
{
var welcomeClient = new WCFWindowsServiceReference.WelcomeClient();
Console.Write("Enter your name : ");
Console.WriteLine(welcomeClient.WelcomeMessage(Console.ReadLine()));
Console.ReadLine();
}
}
}
8) Your WCF service consumer console application is ready. Execute the application to see the result.
![]() |
| WCF Service - WCF Windows service consumer application output. |
Following few articles might be of your interest -
1) How to self host the WCF service?
2) How to consume WCF service in ASP.net?
3) How to host WCF service in IIS?
4) How to enable WCF tracking and MessageLogging?
Sharing is Caring »»
|
|
|
Tweet |





