MARKAND Bhatt
MARKAND Bhatt

Reputation: 2630

Error while accessing wcf-rest function

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.

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

Upvotes: 0

Views: 616

Answers (1)

Erix
Erix

Reputation: 7105

Try using "GET" not "Get"

It's case sensitive apparently.

[WebInvoke(Method = "GET" ...

Upvotes: 1

Related Questions