4

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.

carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
Alex Avrutin
  • 1,344
  • 2
  • 17
  • 24

1 Answers1

6

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.

Jeff Ogata
  • 56,645
  • 19
  • 114
  • 127
  • Yes, you're correct. For audience: well, WCF/WebHttp/WebAPI is really sensitive to parameter types. For boolean parameters, make sure that you specify value as true/false, not as 1/0. It is somewhat funny, but while it can recognize enums, it is unable to parse booleans if they are expressed by numerics. – Alex Avrutin Oct 04 '11 at 16:38
  • @AlexAvrutin: I don't think it's that strange, Enums are supported by the framework, as are Booleans. However, in .NET the only permissible values are 'true' and 'false'. '0' and '1' are not Booleans, they're integers and there's not implicit conversion. – nicodemus13 Feb 19 '12 at 10:32