Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating Web API Hello World
Message
 
 
À
18/12/2016 09:12:52
Information générale
Forum:
ASP.NET
Catégorie:
Visual Studio
Divers
Thread ID:
01645380
Message ID:
01645479
Vues:
39
Yes, (stupid me; sorry).
I have a basic/newbie question (feel free to ignore my questions; Sunday is your day of rest).
Say I create a Web API project that should "receive" two value from a Windows (or some other) application and update something in the database.
What what be (in pseudo code) the endpoint called from the Windows application?

>Looks like the app is running - some things can't be add when, for example, you are debugging ??
>
>>Attached is the image of the menu.
>>
>>>Just add a regular class and paste the code into it. If you are adding yours from scratch then all that matters is that the class be derived from ApiController as in the example....
>>>HTH
>>>
>>>>I wanted to add your example of the ApiController to the project that VS created (for learning/testing). When I right-mouse click on the Controllers folder I don't see how I can add it. The item Controllers is grayed. What am I not understanding?
>>>>
>>>>>> Like, do I need to know how the routing works, in MVC?
>>>>>
>>>>>Not if you use attribute routing. It's one (probably the main) advantage. e.g.:
    [RoutePrefix("api/chat")]
>>>>>    public class MyChatController : ApiController
>>>>>    {
>>>>>        [HttpGet]
>>>>>        [Route("/greeting")]
>>>>>        public HttpResponseMessage SayHello ()
>>>>>        {
>>>>>            return Request.CreateResponse(HttpStatusCode.OK, "Hello World");
>>>>>        }
>>>>>        [HttpGet]
>>>>>        [Route("/farewell")]
>>>>>        public HttpResponseMessage GoodBye()
>>>>>        {
>>>>>            return Request.CreateResponse(HttpStatusCode.OK, "See you later");
>>>>>        }
>>>>>    }
So the routing is controlled solely by the RoutePrefix and Route attributes rather than the method names: e.g:
http://mysite.com/api/chat/greeting
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform