【发布时间】:2011-09-17 05:00:55
【问题描述】:
我有合同:
[OperationContract]
[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, UriTemplate = "GetCategoriesGET/{userIdArg}", BodyStyle = WebMessageBodyStyle.Bare)]
List<Video> GetVideosGET(string userIdArg);
[WebInvoke(Method = "POST", UriTemplate = "evals")]
[OperationContract]
void SubmitVideoPOST(Video videoArg, string userId);
我有实现方法:
public List<Video> GetVideosGET(string userIdArg)
{
List<Video> catsToReturn = new List<Video>();
if (Int32.Parse(userIdArg) == 1)
{
catsToReturn = catsForUser1;
}
else if (Int32.Parse(userIdArg) == 2)
{
catsToReturn = catsForUser2;
}
return catsToReturn;
}
public void SubmitVideoPOST(Video videoArg, string userId)
{
}
当我浏览到:
http://localhost:52587/Api/Content/VLSContentService.svc/GetCategoriesGET/1
我收到此错误:
“/”应用程序中的服务器错误。 操作 'SubmitVideoPOST' 的 合同“IVLSContentService” 指定多个请求正文 要序列化的参数 任何包装元素。最多一具尸体 参数可以不被序列化 包装元素。要么删除 额外的身体参数或设置 BodyStyle 属性 WebGetAttribute/WebInvokeAttribute 到 包裹起来。
当我为 POST 添加新方法(我没有尝试访问)时,我才开始在 Get 请求上收到此错误,这是什么意思?我不能使用多个参数吗?
【问题讨论】: