0

is it possible to use out attribute in a Api Controller method? I'm using C#. for exp:

  [HttpGet]
public string GetWhatever(string type, string source,out int errorCode, out string errorMessage)

if it is, an example of how to call it and get the out value would be great.

Sarath Subramanian
  • 20,027
  • 11
  • 82
  • 86
Michel
  • 103
  • 6

2 Answers2

2

No, this is not possible. Only the return value is used and sent to the client.

You should sent a proper HTTP status code and the error message in body. Have a look at this: http://www.asp.net/web-api/overview/error-handling/exception-handling

Martin Lantzsch
  • 1,851
  • 15
  • 19
1

I believe you miss-understand the usage of the Web API. Your Web Api method will not be called like any other C# class method, unless you access the library directly and reference the api controller and its method like any other C# class.

The method will be called via the ASP.NET action selector and that will depend on your HTTP verb (GET, PUT, POST, DELETE or PATCH) and depending on the type and the number of your parameters.

Now your method can return your data or returns error depending on your situation, but eventually all your responses will convert to statuscode/content/error,...etc which is what the HTTP protocol understands and deals with.

for example your method can return Ok Status code (200), or Notfound status code 404 depending on where your request found the requested resource or not.

You can start with this article about Web API 2, hopefully you get a better understanding.

Hope that helps.

Omar.Alani
  • 4,050
  • 2
  • 20
  • 31