Hosting WCF service in Console Application

This video will explain , how to host a WCF Service in a Console Application

For your reference soure code is as below ,

IService1.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.Text;

 

namespace MultipleEndpoints

{

 

    [ServiceContract]

    public interface IService1

    {

 

        [OperationContract]

        string GreetingMessage(string Name);

    }

 

 

}

 

 

 
Service1.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.ServiceModel.Web;

using System.Text;

 

namespace MultipleEndpoints

{

 

    public class Service1 : IService1

    {

        public string GreetingMessage(string name)

        {

            return "Welcome to WCF " + name;

        }

 

    }

}

 

Hosting Console Application

Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.ServiceModel;

using MultipleEndpoints;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

 

            ServiceHost host = new ServiceHost(typeof(Service1));

            host.Open();

            Console.Write("Service is up and running");

            Console.ReadKey();

            host.Close();

 

        }

    }

}

 

 

App.Config

<?xml version="1.0" encoding="utf-8" ?>

<configuration>

  <system.serviceModel>

    <behaviors>

      <serviceBehaviors>

        <behavior name ="Mg">

          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->

          <serviceMetadata httpGetEnabled="true"/>

          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->

          <serviceDebug includeExceptionDetailInFaults="false"/>

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <!--<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />-->

    <services >

      <service name ="MultipleEndpoints.Service1" behaviorConfiguration ="Mg">

        <endpoint address ="/MyAddress" binding ="basicHttpBinding" contract ="MultipleEndpoints.IService1" />

        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />

        <host>

          <baseAddresses >

            <add baseAddress ="http://localhost:8181/Service1.svc"/>

          </baseAddresses>

        </host>

      </service >

    </services>

  </system.serviceModel>

</configuration>

 


Thanks for watching this video. I hope this was useful. Happy Coding

About these ads

7 thoughts on “Hosting WCF service in Console Application

  1. Pingback: Configuring Multiple End points for WCF Service « DEBUG MODE……

  2. sir
    ur video is very good for self hosting but i want iis host have created one services examples of add,mul methods my of the client consume that services of add methods using tcp protocols and another client consume mul methods http protocols can u give me examples of this type of video sir

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s