Today I would like a post about deploying WCF in IIS to help you avoiding nightmare from error given back by IIS 7 during installation. In the end of this post, you can host a wcf service in your localhost and call it like following
1. Install IIS 7 on your computer. Control Panel –> Programs and Features –> Turn Windows features on or off –> Navigate to “Internet Information Services” –> Select these options, then click on.
2. After installing IIS 7, open your browser and browse to localhost you will have this page if installation was successful.
3. Build your own WCF services and be sure that you have a running one by starting it through Visual Studio. The URL of your service before publishing will have format of http://localhost:port
4. Ok, now we have a running IIS and running WCF Services. What we should do is making them work together. In Visual Studio windows, right click on WCF services project and choose Publish (remember to start your Visual Studio as administrator, otherwise publishing will fail). Let all options in next dialog as default and enter “Target Location” as “C:\inetpub\wwwroot\StudentService\”
5. On Start –> Run –> inetmgr to open IIS Manager
6. In IIS Manager, right click on Default Web Site and Add Application. Enter Alias name for the service and point it to the real directory where the service locates. After creating the application, try to browse it on your browser
7. If you are lucky, your application will run like a charm but I believe that you may be meet one of following error or all of them. ^^
7.1 This configuration section cannot be used at this path. This happens when the section is locked at a parent level. Locking is either by default (overrideModeDefault=”Deny”), or set explicitly by a location tag with overrideMode=”Deny” or the legacy allowOverride=”false”.
Note: When you meet this error you must consider where IIS locates your error. For example, in the image above the error relates to handlers tag. I have this error twice when publish WCF Services, one with handlers and one with modules.
– Navigate to C:\Windows\System32\inetsrv\config
– Right click on file applicationHost.config and open it with Notepad
– Search and find the tag which IIS has error with it and edit overrideModeDefault = “Allow”. Remember to save file before close it
7.2 The Web server is configured to not list the contents of this directory
– In IIS Manager, click on real folder of our service –> click Directory Browsing –> Actions: Open Feature –> Enable
7.3 The page you are requesting cannot be served because of the Multipurpose Internet Mail Extensions (MIME) map policy that is configured on the Web server. The page you requested has a file name extension that is not recognized, and is not allowed.
– Open cmd, navigate to C:\windows\Microsoft.Net\Framework\v3.0\Windows Communication Foundation\ and enter “ServiceModelReg -i”. A successful register looks like following
7.4 Handler svc-Integrated has a bad module “ManagedPipelineHandler” in its module list” error.
– Open Control Panel –> Programs and Features –> Turn Windows features on or off –> Activate “Windows Communication Foundation HTTP Activation” and “Windows Communication Foundation Non-HTTP Activation”
7.5 The server encountered an error processing the request. See server logs for more details.
– Open web.config file, edit includeExceptionDetailInFaults=”false” in serviceBehaviors
<serviceBehaviors> <behavior name="DMLService.StudentServiceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors>
7.6 Failed to generate a user instance of SQL Server due to failure in retrieving the user’s local application data path. Please make sure the user has a local user profile on the computer. The connection will be closed.
– In IIS Manager, click on Application Pools –> DefaultAppPool –> Right click and choose “Advanced Settings”
– Change Identity to Local System
Hope you can deploy your WCF Services smoothly with help of this post. If you need a WCF Services to test yourself, you can download here “DML Service“