Default Protocol Mapping in WCF 4.0

In my previous post, I talked about Default End Point in WCF 4 . If we closely look at the output that by default WCF maps protocol to binding as below.


So if we are not configuring any EndPoint , then for http type base address in default EndPoint created by WCF will have basicHttpBinding.

If we see the above mapping , by default http type is mapped to basicHttpBinding , net.tcp type is mapped to netTcpBinding and so on.

If we want to change this, we can change this default mapping


Now when we do the above change in the Web.Config file then when we do not define any EndPoint then for HTTP type base address, WCF will create the EndPoint with wsHttpBinding.

So to understand more, what I am talking about

1. Create a WCF Service application

2. Create a Service contract as below

 public interface IService1

 string GetData();

3. Implement the Service as below

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService1

 public class Service1 : IService1
 public string GetData()
 return "Hello From Iservice1 ";



4. Now we will host this service in a console application, Create a new console application project. Add reference of WCF service application project and also add reference of System.serviceModel in the console application project.

5. Right click on the console project and add app.config file to console project. Right the below configuration in App.Config

 <?xml version="1.0" encoding="utf-8" ?>
 <protocolMapping >
 <add  scheme ="http" binding ="wsHttpBinding" bindingConfiguration ="" />

6. Now write the below code to fetch the default Endpoint created by WCF

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using WcfService1;

namespace ConsoleApplication1
 class Program
 static void Main(string[] args)

ServiceHost host = new ServiceHost(typeof(WcfService1.Service1),
 new Uri("<a href="http://localhost:8080/service">http://localhost:8080/service</a>"));

 foreach (ServiceEndpoint se in host.Description.Endpoints)
 Console.WriteLine("Address: " +  se.Address.ToString() +
 "  Binding: " + se.Binding.Name +
 " Contract :"+ se.Contract.Name);


And output we would get is


So we can see that how we modified the default mapping using Protocol mapping in System.ServiceModel

Published by

Dhananjay Kumar

Dhananjay Kumar is Developer Evangelist for Infragistics. He is a 8 times Microsoft MVP and well respected Developer Advocate in India.He is the author of 900+ Blog Posts, and can often be found speaking around India at conferences and hosting free workshops for programmers across the country. So far, he has hosted 60 free workshops on various topics like JavaScript, Angular, WCF, ASP.NET MVC, C#, Azure etc. Follow him on twitter @debug_mode for all the updates about his blog posts and workshops. You can send him email at debugmode [at] outlook [dot] com

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s