user1589780
user1589780

Reputation: 73

How to correctly configure a WCF REST service endpoint?

I am planning to host multiple RESTful services based on different contracts. There are a lot of similar questions but my web.config file looks different, I don't know why.

Here is part of my web.config file :

    <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint name="" 
                              helpEnabled="true" 
                              automaticFormatSelectionEnabled="true">
            </standardEndpoint>
          </webHttpEndpoint>
    </standardEndpoints>

Here is my service declaration in my web application :

    RouteTable.Routes.Add(new ServiceRoute("bob/chocolate", new WebServiceHostFactory(), typeof(RESTchocolate)));
    RouteTable.Routes.Add(new ServiceRoute("bob/vanilla", new WebServiceHostFactory(), typeof(RESTvanilla)));

Only the first Route seems to be working (tested using the nice "bob/chocolate/help" endpoint feature of .NET to list the methods available) which does not surprises me really, but how should I modify my web.config file ? Does any of you know how to do this ? Do I need to modify something else ?

For those wondering, my contracts are valid.

I get "Endpoint not found" in a nice .NET display if I try to reach the second endpoint in my browser.

EDIT :

I added the following node to my config file...

    <services>
      <service name="chocolate">
        <endpoint address="bob/chocolate" binding="basicHttpBinding" name="chocolate" contract="RESTapi.IRESTchocolate" />
      </service>
      <service name="vanilla">
        <endpoint address="bob/vanilla" binding="basicHttpBinding" name="vanilla" contract="RESTapi.IRESTvanilla" />
      </service>
    </services>

But I get the same behaviour. The problem is still here

EDIT : and here is my complete config file as requested (without the node above) :

    <?xml version="1.0"?>
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.0" />
        <authentication mode="None"></authentication>
      </system.web>
      <system.serviceModel>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true">
        </serviceHostingEnvironment>
         <standardEndpoints>
          <webHttpEndpoint>
            <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"></standardEndpoint>
          </webHttpEndpoint>
        </standardEndpoints>
      </system.serviceModel>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
      </system.webServer>

    </configuration>

Upvotes: 0

Views: 6977

Answers (1)

Juan Ayala
Juan Ayala

Reputation: 3518

I really recommend you install the WCF REST Service Template 40 and take a look at the bootstrap.

Web.config

<standardEndpoints>
  <webHttpEndpoint>
    <!-- 
        Configure the WCF REST service base address via the global.asax.cs file and the default endpoint 
        via the attributes on the <standardEndpoint> element below
    -->
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
  </webHttpEndpoint>
</standardEndpoints>

Global.asax

// Edit the base address of Service1 by replacing the "Service1" string below
RouteTable.Routes.Add(new ServiceRoute("Service1", new WebServiceHostFactory(), typeof(Service1)));

Upvotes: 1

Related Questions