locked
Can't get REST services working in IIS RRS feed

  • Question

  • I can't seam to figure out how to get my rest service working when deployed to IIS. Everything works fine while using a console host, but when trying to do the same thing using iis or wcf Service Application, I get "The resource cannot be found".

    url:
    http://localhost:8080/rest/test

    code:

    namespace HelloWcfService1
    {
        [ServiceContract]
        public interface IService1
        {
            [OperationContract]
            [WebGet(UriTemplate = "/rest/{value}")]
            string GetData(string value);
        }

        public class Service1 : IService1
        {
            public string GetData(string value)
            {
                return string.Format("You entered: {0}", value);
            }
        }
    }

    config:

    <?xml version="1.0"?>
    <configuration>
     <system.web>
      <compilation debug="true">
      </compilation>
      <authentication mode="Windows"/>
     </system.web>

     <system.serviceModel>
      <services>
       <service name="HelloWcfService1.Service1" behaviorConfiguration="HelloWcfService1.Service1Behavior">
        <endpoint address="" binding="webHttpBinding" contract="HelloWcfService1.IService1">
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
      </services>
      <behaviors>
       <serviceBehaviors>
        <behavior name="HelloWcfService1.Service1Behavior">
         <serviceMetadata httpGetEnabled="true"/>
         <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
       </serviceBehaviors>
      </behaviors>
     </system.serviceModel>
    </configuration>

    Thanks


    wmmihaa
    Friday, November 14, 2008 10:38 PM

Answers

  • You need an endpoint behavior with <webhttp /> to enable the webhttp extension. Like below.

    <system.serviceModel> 
      <services> 
       <service name="HelloWcfService1.Service1" behaviorConfiguration="HelloWcfService1.Service1Behavior"
        <endpoint address="" binding="webHttpBinding" behaviorConfiguration="webBinding" contract="HelloWcfService1.IService1"
        </endpoint> 
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
       </service> 
      </services> 
      <behaviors> 
       <serviceBehaviors> 
        <behavior name="HelloWcfService1.Service1Behavior"
         <serviceMetadata httpGetEnabled="true"/> 
         <serviceDebug includeExceptionDetailInFaults="true"/> 
        </behavior> 
       </serviceBehaviors> 
       <endpointBehaviors> 
            <behavior name="webh"
              <webHttp/> 
            </behavior> 
          </endpointBehaviors> 
      </behaviors> 
     </system.serviceModel> 


    --Steve Barbour
    Saturday, November 15, 2008 12:54 AM