Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET 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
Posted 19-Dec-12 2:53am
Edited 19-Dec-12 4:49am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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:
 
[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.
 
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;
} 
  Permalink  
v3
Comments
Oleksandr Kulchytskyi at 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)

  Print Answers RSS
0 OriginalGriff 392
1 CPallini 365
2 Sergey Alexandrovich Kryukov 348
3 BillWoodruff 264
4 George Jonsson 255
0 OriginalGriff 5,095
1 CPallini 4,285
2 Sergey Alexandrovich Kryukov 3,767
3 George Jonsson 2,941
4 Gihan Liyanage 2,386


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100