Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7955445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:42:51+00:00 2026-06-04T03:42:51+00:00

I am looking at the following tutorial from Microsoft. As per this tutorial, In

  • 0

I am looking at the following tutorial from Microsoft. As per this tutorial,

In the first example, “products” matches the controller named
ProductsController. The request is a GET request, so the framework
looks for a method on ProductsController whose name starts with
“Get…”. Furthermore, the URI does not contain the optional {id}
segment, so the framework looks for a method with no parameters. The
ProductsController::GetAllProducts method meets all of these
requirements.

What happens if there are two methods like GetAllProducts() and GetSoldProducts()? Both have no parameters.

Your First Web API Tutorial

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T03:42:52+00:00Added an answer on June 4, 2026 at 3:42 am

    Assuming you’re using the default routes the short answer is : the method defined first (at the top) of your class will be called. the other method is inaccessible.

    NOTE : the beta behaved as above for ‘matching multiple methods’ – the RC & Release version is a bit more OCD. It throws an error if there are multiple potential matches. This change removes the confusion of multiple ambiguous matches. At the same time, it reduces our ability to mix REST and RPC style interfaces in the same controller, relying on the order & overlapping routes.

    Stealing liberally from another post I wrote on the topic:

    WebAPI Matching Semantic

    The matching semantic used by WebAPI is fairly simple.

    1. It matches the name of the action with the verb (verb = get? look for method starting with “get”)
    2. if a parameter is passed, the api seeks an action with a parameter

    So in your code sample a GET request without a parameter matches the Get*( ) function without an parameters. A Get containing and ID looks for a Get***(int id).

    Examples

    While the matching semantic is simple, it creates some confusion for MVC developers (well at least this developer). Lets look at some examples :

    Odd Names – Your get method can be named anything, so long as it starts with “get”. So in the case of a widget controller you can name your functions GetStrawberry() and it will still be matched. Think of the matching as something like : methodname.StartsWith("Get")

    Multiple Matching Methods – What happens if you have two Get methods with no parameters? GetStrawberry() and GetOrange(). As best I can tell, the function defined first (top of the file) in your code wins …strange. This has the side effect of making some methods in your controller unreachable (at least with the default routes)….stranger.

    UPDATE

    @WinFXGuy – This was a bit long to put in a comment, but …

    Don’t jump to conclusions! I tried to answer the question you posed, but that’s only half the story. There is plenty you can do to change the default behavior.

    First, WebAPI supports much of the oData spec. If you bubble an IQueryable up to your controller, oData paramaters are automatically integrated with the query object. It takes parameters like $filter, $top, and $skip. So you in your case you can write one method and pass something like $filter=sale_date neq null.

    Additionally, you can apply the [ResultLimit] attribute to prevent people asking for 15 billion records.

    Second you can modify the routes. The default routes aim towards a RESTful api, where you generally have 1 controller per entity. You can change the routes and make it RPC style.

    If you look at my linked post I explain how I kept the default route binding, added ‘sub folders’ and also allowed additional method calls for scenarios where i needed GetAllProducts() and GetSoldProducts().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am following this tutorial on using the client-object model. And just starting from
I'm looking at the following API: http://wiki.github.com/soundcloud/api/oembed-api The example they give is Call: http://soundcloud.com/oembed?url=http%3A//soundcloud.com/forss/flickermood&format=json
Looking in this StackOverflow question it uses the following to send emails: System.Net.Mail.SmtpClient Is
I was looking at some code from a tutorial for creating a carousel menu
I'm trying to use Ajax with my CRUD. I'm following this tutorial . I
I'm following through the tutorial from the book Agile Web Development with Rails and
i'm following a tutorial on iPhone on how to display data from a remote
I'm following this tutorial for using OpenAL in C++: http://enigma-dev.org/forums/index.php?topic=730.0 As you can see
Let's take the Django tutorial. In the first part we can find this model:
Im following a tutorial where they have this line: int callDate = c.getInt(dateColumn); Next,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.