【发布时间】:2011-12-23 16:00:21
【问题描述】:
我用这样的帖子做了我的方法:
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
List<Human> GetHuman(UserEnteredName humanName);
UserEnteredName 类只有一个属性 - 字符串。
而且它有效。但是,我需要让它被获取,而不是发布。
我试过这个:
[WebInvoke(Method= "GET", UriTemplate = "GetHuman?username={John}",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
但它不起作用。我需要改变什么?
【问题讨论】:
-
发布错误..“不起作用”是什么意思?
-
@andreapier 错误是 500 内部服务器错误。
-
也许您正试图从一个不是基础域的域中获取一些 json?即:您的基本域是 www.mydomain.com 并且您正在从 inner.mydomain.com 进行 ajax 调用?
-
@andreapier 我尝试使用 UriTemplate = "Service1.svc/json/GetHuman?custName=John",仍然没有结果。
-
我只是想知道您是否试图违反同源政策。在这种情况下,您需要使用 jsonP 而不是经典 json。让我知道。顺便说一句,漂移是正确的,之前尝试一下