asp.net - What kind of datatypes should I use for the return value of a Web API method? -


I have a web API controller that gives data to my clients the code looks like this:

  [http gate] [action name ("retrieve")] public inenemable & lt; Reference & gt; Recover (intisID) {returns _referseva Retrieve (Topic ID); }   

Can anyone tell me that it is necessary to specify ActionName?

In addition, should I return an IEEEMERABLE, an ILIT or something else?

I assume that your ASP.NET routing setup is correct, you ActionName

  secure void Application_Start () {RouteTable.Routes MapHttpRoute ("0", "{controller} / {action} / {arg1} "); }   

match

Whatever you return, Fully based on your MediaType formatter, the default of which is XmlFormatter and JsonFormatter . These can be found in the global configuration. Configuration. Formats will be selected on the basis of and the client provided by the accepted header.

We, for example, use our feedback for formatting, configured by:

  secure void Application_Start () {RouteTable.Routes.MapHttpRoute ("0" , "{Controller} / {action} / {arg1}"); MediaTypeFormatterCollection Formats = Global Configuration. Configuration. Formats; Formatters.Remove (formatters.XmlFormatter); Var jsonFormatter = Global Configuration. Configuration. Formats. Jason Format Serializer settings; JsonFormatter.Formatting = formatting. Indented; JsonFormatter.ContractResolver = New CamelCasePropertyNamesContractResolver (); }   

This tells WebApi to reject any XML formatting and returns JSON only using JSON.Net contract resolver. JSON.Net supports serialing IEnumerable .

However, I would recommend returning a HttpResponseMessage instead. It also allows you to set the status code (it still uses the media type formatter, it's just a clean cover). You can use it like this:

  [HTTPGet] Recover Public HTTPPPS Passage (IntecId) {var reaction _referseva. Retrieve (topic id); Return request. Create Response (HTTPTas Code. OK, Feedback); }    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -