Click here to Skip to main content
11,582,911 members (76,407 online)
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 365
1 Sergey Alexandrovich Kryukov 220
2 virusstorm 209
3 Kornfeld Eliyahu Peter 165
4 Andy Lanng 139
0 OriginalGriff 1,403
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 696
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 503


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 20 Dec 2012
Copyright © CodeProject, 1999-2015
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