问题描述
当我尝试访问wcf-rest时出现以下错误。
合同''SelectorFront''中的操作''登录''指定方法''获取''在WebGetAttribute / WebInvokeAttribute上,但Method唯一允许的值是GET或POST。 ''System.ServiceModel.Description.WebScriptEnablingBehavior''不支持其他值。
我创建了一个wcf-rest, 1方法登录并有一个参数用户名
这是我的函数调用。
http:// localhost:2664 / FrontService.svc / Login?Username =最高
我的wcf如下
界面
I am getting following error when i try to access the 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. Other values are not supported by ''System.ServiceModel.Description.WebScriptEnablingBehavior''.
I have created a wcf-rest, with 1 method "Login" and has one parameter "Username"
This is my function call.
http://localhost:2664/FrontService.svc/Login?Username=max
And my wcf is as following
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
推荐答案
[OperationContract]
[WebInvoke(Method = "Get", UriTemplate = "Login?UserName={UserName}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string Login(string UserName);
之后您的参数可能会成功路由到方法参数名为UserName。
And after that you parameter might be successfully routed to method parameter called 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;
}
这篇关于访问wcf-rest函数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!