0

当我尝试访问 wcf-rest 时出现以下错误。

合同“SelectorFront”中的“登录”操作指定 WebGetAttribute/WebInvokeAttribute 上的“Get”方法,但 Method 的唯一允许值是 GET 或 POST。“System.ServiceModel.Description.WebScriptEnablingBehavior”不支持其他值。

我创建了一个 wcf-rest,有 1 个方法“登录”并有一个参数“用户名”这是我的函数调用。

localhost:2664/FrontService.svc/Login?Username=max

我的 wcf 如下

界面

[OperationContract]
[WebInvoke(Method = "Get", UriTemplate = "/Login/{UserName}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] 
string Login(string UserName);

服务

public string Login(string UserName)
{
tblUser obj = (from m in dataContext.tblUsers
where m.UserName == UserName
select m).First();
JavaScriptSerializer oSerializer = new JavaScriptSerializer();
string sJSON = oSerializer.Serialize(obj);
return sJSON;
}

这个问题的解决方案是什么

4

1 回答 1

1

尝试使用“GET”而不是“Get”

显然是区分大小写的。

[WebInvoke(Method = "GET" ...
于 2012-12-19T13:38:45.347 回答