Midnight_Blaze Midnight_Blaze - 4 months ago 38
C# Question

Web API and C# out Values

I have a service that contains a lot of functions with out parameters to return a few extra parameters.

I was wondering if it's possible to call a regular asp.NET web api service with out parameters and receive a value(in the form of out parameters, separate from the return value) from the service.

If it is possible, could you elaborate on what I need to do to achieve this?

Any help will be well appreciated.


No, this is not possible. The response from WebAPI will be a normal HTTP response with a body where the serialized returned data will be.

Of course, as usual, your response can be a complex object to serialize and you can include those out returns as members of it. For example:

public IHttpActionResult GetResponse(int id)
    int outputInt;
    string outputString;

    YourMethodWithOutParameters(id, out outputInt, out outputString);

    return Ok(new
        Id = id,
        OutputInt = outputInt,
        OutputString = outputString,