An app new project in order to fashion, with the ASP. NET Web API, perhaps I am not too familiar with, after a few days of painstaking research, the Web API really does not use, it belongs to incompatible.
Create a new API controller, probably the following method
Public ienumerable<string> Get (); Public string Get (int ID); Public void Post ([frombody]string value); Public void Put (int ID, [frombody]string value); Public void Delete (int id);
The return value of these methods obviously does not meet the requirements, for example, when the iOS or Andriod side request Delete, delete is not successful, it is not known, so must be wrapped in the return results, similar
Public class Myresponse { publicintgetset;} Public string Get Set ; } Public Object Get Set ; } }
Then the API controller method becomes
Public myresponse Get (); Public Myresponse Get (int ID); Public Myresponse Post ([frombody]string value); Public Myresponse Put (int ID, [frombody]string value); Public Myresponse Delete (int id);
So here's the problem------------------------------------------------
1. In public myresponse Get (int id); method, if Content-type is Application/xml, then the serialization error will be reported, there is no, not very convenient to return XML, my solution is: Remove Xmlformatter in global, the client is used application /json Request
Public Myresponse Get (int ID) { var model = userrepository.find (ID); return New Myresponse () { = model };}
If so, why not use the Jsonresult in MVC?
2. I understand the purpose of the Web API design, what semantics ah, what resources ah, but so many methods are not serious enough to use Ah, such as user, the need to register, login, change the password, modify data, verify the uniqueness of the user name, etc., a get PUT POST delete how enough, Of course I know there are other type, but those English words too jerky, tell the terminal friend this with LOCK, that with SEARCH? So finally I changed the routing, like
CONFIG. Routes.maphttproute ( "actionapi", "api/{ Controller}/{action}/{id}", new {id = routeparameter.optional} );
Then hit the HttpPost httpput on the action. Wait, all this kind of, why do not use MVC,MVC in the action not the same can be called get post
3. Think this is the end, no, do the terminal colleague said, you put the method, you can not use AH. Perhaps, like Appcan this middleware, perhaps only support get,post, after I finally change httpput httppost, everything is okay
Look at the so-called Web API, is this still a Web API? In fact, with MVC in Jsonresult no different, do not know why Microsoft out of such a thing??
Is there no one who spits out the Web Api for the ASP?