This article is an attempt to depict steps may needed to configure IIS for hosting WCF application. An important thing that should be considered is that all user do not face following situations. First of all I try to create a simple WCF application and then I try to publish this simple WCF simple application.
In order to create a WCF application we just need to know ABC of WCF application which are Address, Binding and Contract. (You can download code from [here](https://localhost/be/admin/Pages/resources/WCFConfigIIS/AccountSolution.zip))
First of all I created a blank solution with Visual Studio 2008 by clicking File > New > Project and selecting Other Project Types > Visual Studio Solutions > Blank Solution
I created solution named AccountSolution. I added new project named **Accounting **by right clicking on AccountingSolution and selecting Add > New project menu. In the next step I added reference of System.ServiceModel to project references.
I changed name of class1.cs to IAccount.cs and I added new class named AccountService.cs. Here is code for IAccount and AccountService: IAccount.cs
[sourcecode language="csharp"] using System; using System.Text; using System.ServiceModel; namespace Accounting { public class AccountService : IAccount { #region IAccount Members public int GetBalance(int accountNumber) { Random rnd = new Random(1000000); return Convert.ToInt32(rnd.Next()); } #endregion } }[/sourcecode]
I added new web site named WCFServiceAccount and added new project reference of Accounting. Since I added project reference to Accounting project, cs under App_Data folder is no longer needed. So let delete two cs file under App_Data.
![](https://gkasoq.bay.livefilestore.com/y1plDs_sJrdofjmxAJx5KLB1IRyo8OQaej-EbkO50xRPY-imFFs90p8YcQSZyn_32U0clWyp_dGQuQPHeD8T2wk4VK1hJPUhpQz/DeleteServiceFile.jpg?psid=1)
I changed Service.svc source to:
<%@ ServiceHost Language="C#" Debug="true" Service="Accounting.AccountService"%>
Setting Service and end points:
In order to setService and end points I used WCF Configuration option by right-clicking on web.config.
**Tip**: Sometimes "Edit WCF Configuration" does not appear in right-click menu. Once open "WCF Service Configuration" from tools menu and close it, this cause menu appear next time in right click menu.
I set first service name to Accounting.AccountService by browsing Accounting.dll in bin directory.
![](https://public.bay.livefilestore.com/y1pB_4Kia8qCvnVm84Z_mAPdTLsttzeYRSgavEDmipD1J2TQnRIww9aCgWUtkzJgmgjbpYQ4AJ-X6_t_fQTagoemg/WCFConf1.jpg?psid=1)
And I set first end point contract attribute to Accounting.IAccount and delete second end point.
![](https://public.bay.livefilestore.com/y1pNQJ7zjCYsuC64j1u4mzjceRtIOIUwlgh5uoo41IKuJ8l1aAoJRut7RFqtruUwN9nmq2lzezxzG81uNdDPTbGCA/WCFConf2.jpg?psid=1)
And at last save the WCF configuration and build solution. Before running web site let set WCFServiceAccount as startup project and set Service.svc as start page. Our web site is ready to be executed. After successful execution let host our website to local IIS. Simply website could be hosted by publishing web site to local IIS. If IIS is installed before visual studio 2008 you may not face with any following errors and simply you can jump next step.
I tried to publish WCFServiceAccount by right clicking on Web site project and selecting "…" then Local IIS but I've got following errors. (My windows was Vista Ultimate)
To Access local IIS Web sites, you must install the following IIS component. * IIS 6 Metabase and IIS 6 Configuration Compatibility * ASP.NET * Windows Authentication ![](https://public.bay.livefilestore.com/y1pTZqdAli9pFNV3Ue4EJsjyy7yxI73MHpJ2qV7eQ4t1HetvropmejZs60FD3KRdvxQHYuUzqycVYL_ZiuLoGGF1g/LocalIIS.jpg?psid=1)
Configuring IIS to publish a web site (Specially WCF web site):
To rectify mentioned errors I've found a document in [Technet](https://technet.microsoft.com/en-us/library/bb397374.aspx) for installing IIS6 Metabase and IIS 6 Configuration
To install the IIS 6.0 Management Compatibility Components by using the Windows Vista Control Panel 1. Click Start, click Control Panel, click Programs and Features, and then click Turn Windows features on or off. 2. Open Internet Information Services. 3. Open Web Management Tools. 4. Open IIS 6.0 Management Compatibility. 5. Select the check boxes for IIS 6 Metabase and IIS 6 configuration compatibility and IIS 6 Management Console. 6. Click OK.
Pasted from <[https://technet.microsoft.com/en-us/library/bb397374.aspx](https://technet.microsoft.com/en-us/library/bb397374.aspx)>
Following image shows how to install "IIS6 Metabase and IIS 6 Configuration ". Surprisingly you can set other option such as Installing ASP.NET and Windows Authentication.
![](https://public.bay.livefilestore.com/y1p98ev7XdDN9VOCAtu6E64aR9cfG1_-lRJRZk1r9BzkreaCp8mrRiBVTmCrdjkV88tdxHH926kCoEiQjtb9yEIkw/WindowsFeatures2.jpg?psid=1)
Alternatively, For installing ASP.NET you can use visual studio command prompt and running aspnet_regiis with -i parameter:
aspnet_regiis -i
Publishing WCFServiceAccount to local IIS:1. Right click on WCFServiceAccount select publish from menu ![](https://public.bay.livefilestore.com/y1psS3DvG852bzs4I8falh5ecsbtliNY19pE18ZF-zi6SMa9U3wOybrBRvrJ_QbUaTjWZs--NNgKBV-3f_CWAYTPw/PublishWebSite.gif?psid=1) 2. Select local IIS option 3. Select create new application icon 4. Type web application (e.g. WCFServiceAccount) ![](https://public.bay.livefilestore.com/y1p8G2-IOJpyazU2KdzmRewVDyxiiFsckgqy4jdyopSmKNsJq3f5uv67yZ1YuKnhkPSEh9EU7wc_iRy3VBExsMQjg/PublishWebSiteIIS.gif?psid=1) 5. Now open a browser to test your application "https://localhost/WCFServiceAccount/Service.svc" 6. Then select Open button If you get following error:
# Server Error in '/WCFServiceAccount' Application.
# ## *Configuration Error* **Description: **An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.**Parser Error Message: **Unrecognized configuration section system.serviceModel. **Source Error:**
|