Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
C#
[OperationContract]
[WebInvoke(Method = "Get", UriTemplate = "/Login/{UserName}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] 
string Login(string UserName);


Service

C#
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
Posted
Updated 19-Dec-12 4:49am
v2

1 solution

Hi , I suppose that this little issue hidden behind the scene of your Uri template.
So, obviously, you could try declare your method in next format:

C#
[OperationContract]
[WebInvoke(Method = "Get", UriTemplate = "Login?UserName={UserName}", ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string Login(string UserName);


And after that you parameter might be successfully routed to method parameter called UserName.

C#
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;
} 
 
Share this answer
 
v3
Comments
Oleksandr Kulchytskyi 20-Dec-12 10:49am    
And i have forgotten to add url to call that service.
In your case it will remains the same: http://localhost:2664/FrontService.svc/Login?UserName=max

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900