Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

Calling a WCF Self Hosted Console Application

, 9 Jun 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
In previous WCF Tutorial, we discussed about different hosting options available for a WCF Service. We also implemented hosting a WCF Service in a Console Application. Now in this part, we are going to call our already console hosted StudentService from a client. I’ll strongly recommend to go

In previous WCF Tutorial, we discussed about different hosting options available for a WCF Service. We also implemented hosting a WCF Service in a Console Application. Now in this part, we are going to call our already console hosted StudentService from a client. I’ll strongly recommend to go through previous WCF Tutorial for creating and hosting a WCF Service in a Console Application.

Just to recap, what we did in previous post:

  • Created a StudentService Class Library
  • Add a Console Application to solution
  • Hosted the WCF service in Console Application
  • Run the hosted Service

Now, when the self hosted service is live and listening at following address:
            http://localhost:4321/StudentService

We will create a new client application to consume this self hosted WCF service. Let’s add a new Console Application project to existing solution as:

Client Application

For client application to communicate with our WCF Service “StudentService”, we will implement a proxy class. Windows Communication Foundation (WCF) supports multiple ways to generate proxy as:

  • Adding Service Reference to Client
  • Using Tool i.e. SvcUtil.exe, or
  • Implement ClientBase class.

Each proxy generate approach has some pros and cons that we will discuss in a separate WCF Tutorial but for this implementation, we will use the first approach i.e. Adding a Service Reference to client.

Now, right click on ClientApp project and choose “Add Service Reference”, following dialog will appear:

Add Service Reference

In address Textbox, paste the StudentService URL and press “Go” button. This tool will search for the service and list all available WCF services in Services area as shown. Provide a meaningful name for Namespace and press “OK” button.
Note: WCF Service must be running before we press the “Go” button. Also System.ServiceModel must be referenced to ClientApp project as we did in case of StudentHost application.

Under Service Reference, StudentProxy will be added as shown in below diagram:

WCF Proxy

As a new proxy is added to ClientApp, we will use this to call our WCF Service and get the output. Here is the detailed code for calling our Windows Communication Foundation StudentService.

WCF Client

Now, its time to run the application and see the output. First run the WCF host application and then client. You will see the following result:

WCF Hosting

This WCF Tutorial is completing the previous one using step by step approach and hopefully will be useful for understanding WCF Self hosting in a more practical way.

The post Calling a WCF Self Hosted Console Application appeared first on WCF Tutorial.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Imran Abdul Ghani
Software Developer (Senior)
United Arab Emirates United Arab Emirates
Imran Abdul Ghani has more than 10 years of experience in designing/developing enterprise level applications. He is Microsoft Certified Solution Developer for .NET(MCSD.NET) since 2005. You can reach his blogging at WCF Tutorials, Web Development, SharePoint for Dummies.
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141030.1 | Last Updated 9 Jun 2014
Article Copyright 2014 by Imran Abdul Ghani
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid