I wrote a simple REST service in WCF in which I created 2 methods using the same URI pattern, but with a different method (POST and GET). For the GET method, I also send additional request parameters as follows:
[WebInvoke(Method = "POST", UriTemplate = "users")] [OperationContract] public bool CreateUserAccount(User user) { //do something return restult; } [WebGet(UriTemplate = "users?userid={userid}&username={userName}")] [OperationContract] public User GetUser(int userid, string userName) { // if User ID then // Get User By UserID //else if User Name then // Get User By User Name //if no paramter then do something }
when I call CreateUserAccount with the POST method, it works fine, but when I call the GetUser method using GET and sending only one query string parameter (userID or UserName), it gives the error "HTTP method not allowed", but if both parameters are sent , wokrs great.
Can anybody help me?
source share