views:

312

answers:

1

I am currently writing a RESTful WCF service in C# using VS 2005. I am hosting the service through IIS and can browse to the .svc, but whenever I try to navigate to any of the URIs I get a 404 error. If I run the wcftestclient (included with VS 2008) then I am able to see the methods, so I know the service is functioning. The problem seems to be with the REST portion of the implementation.

This is my web.config:

<system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
        <service behaviorConfiguration="ServiceBehavior" name="MyAPI">
     <endpoint binding="webHttpBinding" contract="IExternalAPI"/>
     <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange"/>
        </service>
    </services>
    <behaviors>
        <endpointBehaviors>
     <behavior name="ServiceBehavior">
         <webHttp/>
     </behavior>
        </endpointBehaviors>
        <serviceBehaviors>
     <behavior name="ServiceBehavior">
         <serviceMetadata httpGetEnabled="true"/>
     </behavior>
        </serviceBehaviors>
    </behaviors>
    </system.serviceModel>

This is the contract:

[ServiceContract()]
    interface IExternalAPI {
    [OperationContract]
    [WebGet (BodyStyle=WebMessageBodyStyle.Bare,ResponseFormat=WebMessageFormat.Json,UriTemplate="{APIKey}/Favorites/{userId}")]
    string GetFavoritesList(string APIKey, string userId);

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Addresses/{userId}")]
    string GetAddressList(string APIKey, string userId);

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Authenticate/{userName}/{password}")]
    string Authenticate(string APIKey, string username, string password);

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Checkout/{orderId}/{userId}/{tip}/{addressId}")]
    string Checkout(string APIKey, string orderId, string userId, string tip, string addressId);

    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/AddToOrder/{templateId}/{userId}")]
    string AddFavoriteToOrder(string APIKey, string templateId, string userId);

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "{APIKey}/Pending/{userId}")]
    string GetPendingOrders(string APIKey, string userId);

    [OperationContract]
    [WebGet(BodyStyle = WebMessageBodyStyle.Bare, ResponseFormat = WebMessageFormat.Json, UriTemplate = "Bob")]
    string TestMethod();
    }

Any help would be greatly appreciated.

+1  A: 

I know this is 4 months after your post, but I am engaged in a similar situation. My config looks almost identical to yours, and I was having the same problem until I added the endpointBehavior key. Try specifying in your service endpoint an explicit reference to your endpoint behavior. Maybe that will help.

<service behaviorConfiguration="ServiceBehavior" name="MyAPI">
    <endpoint binding="webHttpBinding" behaviorConfiguration="ServiceBehavior" contract="IExternalAPI"/>
    <endpoint address="mex" binding="mexHttpBinding"  contract="IMetadataExchange"/>
</service>
Matt Hamsmith