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.

1 Answer 1

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.

2
  • 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. Oct 4, 2011 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. Feb 19, 2012 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.