WebApi make the interface problems encountered summary

Recently wrote an interface requirements for webapi achieved previously had contact with only one side while learning to write! I wrote webapi only used for the interface, and not related to mvc. Generally speaking client calls that I write webapi interface services.

Now the problem I encountered in writing webapi in summary:

Server: first create a blank web application,

                       

Then look at the Tools menu -> Library Package Manager -> NuGet management solution package, and then search Asp.net Web Api, click Install. This brings the required files are automatically added to the reference library inside!

Then add Global.asax file, which is registered in the Start method

 

Add a class DemoController make this class reference ApiController

 

Here is the key I want to say is how the client calls me inside this class of methods:

My class there are two methods,

The first method, there is a parameter. If the client want me to call this method must be plus [FromBody] label, (currently I do not know why)

 

The second method:

 

Methods there are a number of parameters, can not a call like the first, the method must be rewritten as

 

 

That is the parameter set a parameter class, you must pass this way in order to call to the (currently I do not know why)

There are many other problems do not understand, but these two have solved our needs time to continue to study.

Client code

 

 

 

 

Reproduced in: https: //www.cnblogs.com/baishiying/p/3197922.html

Guess you like

Origin blog.csdn.net/weixin_34368949/article/details/93439950