Search code examples
wcfwcf-web-api

WCF/WebAPI: HTTP 500 error when I pass more than one parameter to a WebGet method


I have a very dumb problem but for some reason I am unable to find any cure or information about it on the Net.

Summary: I cannot pass to a WebGet method more than one parameter. If I do, server returns HTTP 500 error and the method does not execute. My code and requests are below.

[ServiceContract]
public class WebmailAPI {
...
[WebGet(UriTemplate= "Webmail?messagetype={messageType}&unreadonly={unreadOnly}&skip={skip}&take={take}")]
    public void Get(MessageType messageType, bool unreadOnly, int skip, int take) {
    ...
    }
 }

Global.ASAX.CS: routes.SetDefaultHttpConfiguration(new WebApiConfiguration() { EnableHelpPage = true, EnableTestClient = true }); RouteTable.Routes.MapServiceRoute("api/");

This request executes fine: http://localhost:9000/api/Webmail/?messagetype=1

This one returns the 500 error:

http://localhost:9000/api/Webmail/?messagetype=1&unreadonly=0&skip=0&take=100

Info: VS2010 SP1 + ASP.NET 4 + Entity Framework June 2001 CTP + latest WebAPI

Thanks for any help in advance!

P.S. I tried to HTML-encode "&" in the query string -- no effect.


Solution

  • Use false instead of 0 for unreadonly:

    http://localhost:9000/api/Webmail/?messagetype=1&unreadonly=false&skip=0&take=100

    See the WCF Web HTTP Programming Model Overview, specifically the UriTemplate Query String Parameters and URLs section for the query string parameter formats by data type.