.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Easy Web
Imran Ghani

Home >> Articles >> WCF >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Create WCF 4.0 Service and Hosting in IIS 7.5 Tutorial

Posted By:Dhananjay Kumar       Posted Date: September 10, 2010    Points: 25    Category: WCF    URL: http://www.dotnetspark.com  

This Tutorial will give step by step walkthrough on how to create a basic WCF 4.0 Service, how to host WCF Service in IIS 7.5 and hot to test service in a client.


This article will give step by step walkthrough
  1. How to create a basic WCF 4.0 Service?
  2. How to host WCF Service in IIS 7.5?
  3. Hot to test service in a client.
Create WCF Service

Create WCF service. Open visual studio select new project and then from WCF tab select WCF Service application to create a new WCF service.


Delete the default code created by WCF from IService1 and Service1.svc.cs
  1. So delete the data contract
  2. Modify the service contract as below. Just make one operation contract to return a string.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService5
   public interface IService1
       string GetMessage();



Host WCF Service in IIS 4.0

Open IIS
  1. Open the command prompt in administrator mode. To do click on Start button then type RUN in search and then in Run window type inetmgr to open IIS.


    Now you will have IIS open like below


  2. Right click on Sites and then click Add Web Site


  3. Now a window will open.


    Give any name of your choice as the site name. I am giving name here HostedWcfService


    Now click on select and choose ASP.Net v4.0 from the drop down.


    Now in the physical path section, we need to give physical path of the service. So to get the physical path of the service, right click on the WCF Service project in visual studio and click open project in windows explorer. Open the project in windows explorer and from address bar copy the path and paste that below. Or you can browse also. Just click on browse button and navigate to project folder of the WCF Service.


    Now at the Binding section select HTTP. Give any port number. I am selecting the port as 4567


    Do not give any name as host name. Leave it blank


    Check the check box Start Web Site Immediately.


    And now click OK on the window.

  4. Now open visual studio command prompt in administrator mode. Right click and select as administrator



    Type the below command

    aspnet_regiis.exe /iru


    You will get the message Finished Installing ASP.Net 4.0

  5. Now go to inetmgr, you would able to see the site you just created in previous step.

Publishing the WCF Service

Go back to WCF Service. Right click and select Publish


On clicking of publish a window will come.


Give a Service URL. You are free to give any Service URL here. Just make sure host name is geeting resolved. In stead of localhost you can give IP address or your machine name also.


Give the name of the site HostedWcfService. We created this site in previous step.


Leave the credential inactive.


Now click on Publish.


You will get the message in bottom publish succeeded

Browsing the service hosted in IIS

Open Inetmgr and right click on site HostedWcfService. Then from Manage Web Site select Browse option.


When you click on browse site will get open in browser


You will get the above error. Just in address bar append Service1.svc with the address to open the service in browser.


And in browser you will get the service up and running.


So now you successfully created and hosted the WCF 4.0 service in IIS 7.5

Testing the Service at client
  1. Create console application project.


  2. Right click and add the service reference.


  3. Give in address the address of service hosted in IIS and click GO.


  4. Call the service as below ,


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using ConsoleApplication1.ServiceReference1;   namespace ConsoleApplication1
       class Program
           static void Main(string[] args)
               Service1Client proxy = new Service1Client();




In this article we saw,
  1. How to create a basic WCF 4.0 Service?
  2. How to host WCF Service in IIS 7.5?
  3. Hot to test service in a client.
I hope this article was useful. Thanks for reading. Happy coding.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend