Unable to Successfully Host a REST Web Service under IIS on LocalHost RRS feed

All replies

  • User-2064283741 posted

    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.

    Monday, June 19, 2017 11:46 PM
  • User-460007017 posted

    Hi Geoff_Olding,

    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:


    Best Regards,

    Yuk Ding

    Tuesday, June 20, 2017 6:08 AM
  • User-1436620486 posted

    Hello there

    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.

    Any help greatly appreciated.

    Thursday, June 22, 2017 12:07 PM
  • User-460007017 posted

    Hi Geoff_Olding,

    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=, Culture=neutral, PublicKeyToken=b77a5c561934e089">
          <section name="behaviors" type="System.ServiceModel.Configuration.BehaviorsSection, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="bindings" type="System.ServiceModel.Configuration.BindingsSection, System.ServiceModel, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" /> .... </sectionGroup>

    Just ensure the WCF feature under .net framework in turn windows features on or off has been installed.

    Best Regards,

    Yuk Ding

    Thursday, June 29, 2017 8:19 AM
  • User-1436620486 posted

    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.

    I followed http://www.c-sharpcorner.com/UploadFile/francissvk/how-to-publish-Asp-Net-web-application-using-visual-studio-2/ to publish the “BlogService” web-site to “c:\localcopy”.

    I installed this published web-site to IIS as per https://docs.microsoft.com/en-us/iis/get-started/getting-started-with-iis/create-a-web-site.

    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:

    <?xml version="1.0"?>

        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
        <compilation debug="true" targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2"/>
          <service name="SimpleRESTService.Service1" behaviorConfiguration="RESTBehavior">
            <endpoint address="" binding="webHttpBinding" contract="SimpleRESTService.IService" behaviorConfiguration="MyEndpointBehavior"/>
            <behavior name="RESTBehavior">
                <serviceMetadata httpGetEnabled="true"/>
                <serviceDebug includeExceptionDetailInFaults="true"/>
            <behavior name="MyEndpointBehavior">
            <add binding="basicHttpsBinding" scheme="https" />
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
        <modules runAllManagedModulesForAllRequests="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.
        <directoryBrowse enabled="true"/>


    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
      WCF Services
        HTTP Activation

    Many thanks

    Geoff Olding

    Thursday, August 10, 2017 10:30 PM