WCF/WebAPI:当我将多个参数传递给WebGet方法时出现HTTP 500错误

Ale*_*tin 4 wcf wcf-web-api

我有一个非常愚蠢的问题,但由于某种原因,我无法在网上找到任何治疗或信息.

简介:我无法向WebGet方法传递多个参数.如果我这样做,服务器返回HTTP 500错误,该方法不会执行.我的代码和请求如下.

[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) {
    ...
    }
 }
Run Code Online (Sandbox Code Playgroud)

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

此请求执行正常: http:// localhost:9000/api/Webmail /?messagetype = 1

这个返回500错误:

HTTP://本地主机:9000/API /网络邮件/为messageType = 1&unreadonly = 0&跳过= 0&取= 100

信息:VS2010 SP1 + ASP.NET 4 +实体框架2001年6月CTP +最新的WebAPI

在此先感谢您的帮助!

PS我试图在查询字符串中对"&"进行HTML编码 - 没有效果.

Jef*_*ata 6

使用false的,而不是0unreadonly:

HTTP://本地主机:9000/API /网络邮件/为messageType = 1&unreadonly =假跳过= 0&取= 100

请参阅WCF Web HTTP编程模型概述,特别是按数据类型查询字符串参数格式的UriTemplate查询字符串参数和URL部分.