Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 644
Midnight_Blaze Avatar asked Sep 04 '26 19:09

Midnight_Blaze


1 Answers

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,
    });
}
like image 166
Fredy Treboux Avatar answered Sep 06 '26 10:09

Fredy Treboux



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!