我的 URL 路径组件太长,我正在尝试将方法从 GET 更改为 POST。我遇到了反序列化问题。这里是服务
public class AppUser : IAppUser
{
//[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, UriTemplate = "AddShop/{shop}")]
[WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, RequestFormat=WebMessageFormat.Json, UriTemplate = "AddShop")]
List<fme.AppUserResult> services.IAppUser.AddShop(string shop)
{
JavaScriptSerializer jss = new JavaScriptSerializer();
fme.AppUser oUser = jss.Deserialize<fme.AppUser>(shop);
return oUser.Add();
}
}
这是请求(如果它少于 260 个字符,它与 GET 一起使用)
{"shopCity":"City","shopState":"State","shopPhone":"Phone","shopName":"Name","shopEmail":"Email","shopHours":"Hours","shopZip":"Zip","shopAddress":"Street"}
我也试过
{"shop":{"shopCity":"City","shopState":"State","shopPhone":"Phone","shopName":"Name","shopEmail":"Email","shopHours":"Hours","shopZip":"Zip","shopAddress":"Street"}}
这是错误:
服务器在处理请求时遇到错误。异常消息是“反序列化 System.String 类型的对象时出错。应来自命名空间“”的结束元素“根”。从命名空间 ''.' 中找到元素 'shopCity'。有关更多详细信息,请参阅服务器日志。异常堆栈跟踪是: