IIS 7 and Above
Unable to Successfully Host a REST Web Service under IIS on LocalHost
Last post Aug 10, 2017 10:30 PM by Geoff_Olding
Jun 19, 2017 09:21 PM|Geoff_Olding|LINK
This is a copy of my post on the WCF forum at
https://social.msdn.microsoft.com/Forums/vstudio/en-US/f675c523-30d2-42d8-8461-4f99f612c31b/unable-to-successfully-host-a-rest-web-service-under-iis-on-localhost?forum=wcf. My original post was on the Universal App Development forum.
I am trying to develop a REST based web service to call from my Universal app.
I plan to put the web service on a server in due course, however for the moment I just want to get it running on my local PC under IIS.
I am using Visual Studio 2015 Community and Windows 10.
I have followed through the following article:
Everything works as documented (except for a few adjustments I needed to make because of Entity Framework version issues).
When I run the service from Visual Studio, everything works correctly.
For example, I can successfully make calls such as:
This works from both IE and fiddler.
When I run the web service project from Visual Studio, it runs the WCF service host utility.
The article does not discuss how to deploy the web service.
I have followed through a number of other articles on how to install a web service in IIS, which I have done on my PC.
None of these work – when I make calls such as
http://localhost:8085/BlogService/GetSomePosts, I just get the standard 404 error.
A lot of the documentation talks about publishing within Visual Studio using “Web Deploy”.
I don’t have a “Publish method” dropdown from which to select “Web Deploy”.
Any help greatly appreciated.
Jun 19, 2017 11:46 PM|Rovastar|LINK
Deploying really is just another word for copying.
You have to somehow get the code onto the web server.
I don't use Visual Studio you should ask on other forums for how to get code out of vs to iis.
Jun 20, 2017 06:08 AM|Yuk Ding|LINK
IIS host the rest service in IIS express in visual studio. If you want to host the WCF rest web service in IIS, you have to create website in IIS and publish the REST service to IIS use web deploy. First of all, please ensure the necessary IIS feature in
turn windows features on or off/server manager has been installed.
This link provide the steps to publish project to IIS:
Before publishing the web application to IIS, you need to create such a website and add a binding host header to host the website.
This link also provide a complete steps to host rest service in IIS:
Remember to access the website with IIS binding instead of IIS express binding. localhost:8085 is the default IIS EXPRESS binding to access the webserivce in visual studio. When you publish to the website to IIS, you have to access the website use IIS site.
This link provide the difference between IIS and express:
Jun 22, 2017 12:07 PM|Geoff_Olding|LINK
Many thnks for your reply.
I am attempting to implement the simple REST service as documented at
https://social.technet.microsoft.com/wiki/contents/articles/1265.hosting-a-wcf-rest-service-on-iis.aspx (the article that you suggest).
When I add the <services> section in web.config under <system.serviceModel>, I get the following error when I hover over the <services> element:
The element ‘system.serviceModel’ cannot contain text.
List of possible elements expected: behaviors, bindings, client, comContracts, commonBehaviors, diagnostics, serviceHostingEnvironment, extensions, protocolMapping, services, standardEndpoints, tracking, routing’.
When I run the application, I get the error “Unrecognized element” with <system.ServiceModel> highlighted.
I am guessing that the “Unrecognized element” refers to <services>.
I am not adding text (whatever that actually might mean), and I am adding a <services> section.
With this in mind, I am unclear on the usefulness of an error message telling me not to add text and telling me that I can add a <services> section.
Jun 29, 2017 08:19 AM|Yuk Ding|LINK
Just ensure you have selected the correct version of .NET version in application pool. .Net 2.0 3.5 use .net 2.0 CLR and .net 4.0 above version use 4.0 CLR. Besides, go to C:\Windows\Microsoft.NET\Framework\<.net verison>\Config\machine.config. Ensure the
service model section group has been registered like
<sectionGroup name="system.serviceModel" type="System.ServiceModel.Configuration.ServiceModelSectionGroup, System.ServiceModel, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="behaviors" type="System.ServiceModel.Configuration.BehaviorsSection, System.ServiceModel, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
..... <section name="bindings" type="System.ServiceModel.Configuration.BindingsSection, System.ServiceModel, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
Just ensure the WCF feature under .net framework in turn windows features on or off has been installed.
Aug 10, 2017 10:30 PM|Geoff_Olding|LINK
Many thanks for your replies.
I would like to include some screenshots in my post but am unable to work out how to do so.
to publish the “BlogService” web-site to “c:\localcopy”.
I installed this published web-site to IIS as per
The call to
http://localhost:8085/BlogService/GetBlogPosts in IE and fiddler still fails.
I then followed the article at
https://social.technet.microsoft.com/wiki/contents/articles/1265.hosting-a-wcf-rest-service-on-iis.aspx to create a new “simpleRESTService” WCF web service application.
As per my post above, the web.config as stated in the article is invalid.
I made my best guess about what the web.config should be:
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
<compilation debug="true" targetFramework="4.5.2" />
<service name="SimpleRESTService.Service1" behaviorConfiguration="RESTBehavior">
<endpoint address="" binding="webHttpBinding" contract="SimpleRESTService.IService" behaviorConfiguration="MyEndpointBehavior"/>
<add binding="basicHttpsBinding" scheme="https" />
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
This seems to be run correctly from within Visual Studio.
Clicking on Ctl F5 produces a list of files to click on, including service1.svc.
I do not understand the instructions “Double click on the ASP.NET Development Server icon on the status bar”, however from running the service I assumed that the port number was
55507, so I ran http://localhost:55507/.
This doesn’t produce the effect pictured in the article.
Instead, it lists the files in the same way as pressing Ctl F5.
To get the effect pictured in the article, I assumed that I needed to use the following URL:
This doesn’t work – it returns the error “Endpoint not found”.
There is a sort of compilation error in Service1.svc:
<%@ ServiceHost Language="C#" Debug="true" Service="SimpleRESTService.Service1" CodeBehind="Service1.svc.cs" %>
The tooltip states “Missing Attribute Value on attribute ‘ServiceHost’.
I am unclear on your paragraph starting “Remember to access the website with IIS binding”,
and your comment “Just ensure you have selected the correct version of .NET version in application pool”.
The service is using The .Net Framework 4.5.2.
There is no corresponding directory at C:\Windows\Microsoft.NET\Framework for me to edit machine.config.
I am unclear which Windows Features I need to turn on.
I have the following:
.NET Framework 3.5 (includes .NET 2.0 and 3.0)
Windows Communication Foundation HTTP Activation
Windows Communication Foundation Non-HTTP Activation
.NET Framework 4.7 Advanced Services