Why is this method not allowed for WebInvoke, but OK for WebGet?
Can someone explain the reason behind this or how it works? IF I do a WebInvoke on the following, it fails (says method not allowed, but if I do a WebGet, it passes). I just want to understand why?
[OperationContract]
[WebGet(UriTemplate = "login/{username}/{password}", ResponseFormat =
WebMessageFormat.Json)]
string Login(string username, string password);
开发者_StackOverflowThe above code, just returns a hard coded string. (No conditional logic)
EDIT: Rewritten somewhat now I've reread the question...
WebInvoke
allows you to specify which verb will be allowed, defaulting to POST. WebGet
requires the client to be using a GET request. In either case, if the wrong verb is used, you'll get "method is not allowed". You were using the browser, so it was making a GET request, so a normal POST-only WebInvoke would reject it, whereas a WebGet would allow it. You could specify Method="GET"
in the WebInvoke
attribute declaration to allow GET, of course.
精彩评论