4

I have written a simple REST Service in WCF in which I have created 2 method using same URI Template but with different Method(POST and GET). For GET method I am also sending additional query 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 method POST it is working fine but when I call GetUser method using GET and sending only one query string parameter(userID or UserName) it is giving error "HTTP Method not allowed" but if send both parameters its wokrs fine.

Can anyone help me?

Rajesh Kumar
  • 2,443
  • 3
  • 28
  • 43
  • you have the same base URI for both, have you tried chaning one from 'users' to something else? Only ask because overloads don't work in web services. – iMortalitySX Oct 29 '12 at 17:43

1 Answers1

5

Do not specify any of the optional parameters and use WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters to access all of them.

Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74