views:

1131

answers:

1

I'm trying to learn how to build RESTful services with WCF by recreating the project on this blog post by Anthony Steele. He uses the following XML in his config to setup the endpoint for the service.

    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8080/greeter"/&gt;
      </baseAddresses>
    </host>

However, when I try to do the same thing in my ASP.NET 3.5 web site's web.config, I am unable to navigate to my service. Here is the XML I'm using:

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="GreeterBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service behaviorConfiguration="GreeterBehavior" name="Greeter">
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:49268/TestREST/webapi/services/greeter"/&gt;
        </baseAddresses>
      </host>
      <endpoint address="" binding="wsHttpBinding" contract="IGreeter">
        <identity>
          <dns value="localhost"/>
        </identity>
      </endpoint>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
  </services>
</system.serviceModel>

I would imagine my configuration would allow me to navigate to http://localhost:49268/TestREST/webapi/services/greeter and see my service. All I get is a resource not found message - am I missing something?

Edit: Part of my problem was my binding was wsHttpBinding. Using webHttpBinding allowed me to use the service correctly - except, the baseAddress config section still has no effect.

+3  A: 

My hunch is that the service endpoint is not being created successfully.

In the service "name" attribute you are not including the FQN (Fully Qualified Name) of the service type. Secondarily, in the endpoint "contract" attribute you are also not including the FQN to the contract type.

On the other hand, this MAY be a port issue. In order to be sure, try running the WcfTestClient.exe that is included in the Visual Studio 2008 distribution. If you can connect to http://localhost:49268/TestREST/webapi/services/greeter/mex, then you know it is not a port issue.

Supposing that you can connect via MEX, then try exercising some of the methods, which would presumably be mapped to http://localhost:49268/TestREST/webapi/services/greeter.

If you are operating on server, see some valuable details about HttpCfg.exe here: http://stackoverflow.com/questions/530286/wcf-servicehost-basichttpbinding-503-error/530474#530474

If you need more details on WcfTestClient, look for them here: http://stackoverflow.com/questions/484717/error-externally-testing-wcf-udp-custom-transport-channel-sample-from-the-windows

Just In Case: copy the sample verbatim and verify that it works as defined, including the config file, before making the slightest deviation from it.

EnocNRoll