简体   繁体   English

访问wcf-rest函数时出错

[英]Error while accessing wcf-rest function

I am getting following error when i try to access the wcf-rest. 当我尝试访问wcf-rest时出现以下错误。

Operation 'Login' in contract 'SelectorFront' specifies Method 'Get' on the WebGetAttribute/WebInvokeAttribute, but the only allowed values for Method are GET or POST. 合同“ SelectorFront”中的“登录”操作在WebGetAttribute / WebInvokeAttribute上指定了方法“ Get”,但是Method唯一允许的值为GET或POST。 Other values are not supported by 'System.ServiceModel.Description.WebScriptEnablingBehavior'. 'System.ServiceModel.Description.WebScriptEnablingBehavior'不支持其他值。

I have created a wcf-rest, with 1 method "Login" and has one parameter "Username" This is my function call. 我创建了一个wcf-rest,使用1种方法“ Login”并具有一个参数“ Username”。这是我的函数调用。

localhost:2664/FrontService.svc/Login?Username=max 本地主机:2664 / FrontService.svc / Login?Username = max

And my wcf is as following 我的wcf如下

Interface 接口

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

Service 服务

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;
}

what is the solution of this issue 这个问题的解决办法是什么

Try using "GET" not "Get" 尝试使用“ GET”而不是“ Get”

It's case sensitive apparently. 显然是区分大小写的。

[WebInvoke(Method = "GET" ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM