简体   繁体   中英

one way method in asp.net web-api

I am a newbie to asp.net Web API service. I want to create a method that does not return any value one-way method. How can I achieve this in asp.net Web API service? I did a lot of search on google but I do not know what exactly should happen. I consume this service from an Android mobile app and the only thing came to my mind is just ignore the returned response from service. Is this possible? this method will send an email to the user.

An HTTP request should always return something , even if it's an empty response which does nothing more than indicate success. Which you can do in Web API with the Ok() response :

return Ok();

the only thing came to my mind is just ignore the returned response from service. Is this possible?

Of course. Any code can ignore the response from any other code. Conceptually it's no different from calling a method and ignoring the returned result. Simply make your HTTP request and then have no handlers for the response.

Note however that it is recommended to at least check for a successful response just to ensure that there wasn't an error. Otherwise, well, there could have been an error and you'd never know.

there will always be a response from an api, even if its just a status code.

if your API method sends an email then I suggest you check for success, if everything is ok return 200, like in the other response, otherwise, return BadRequest and maybe the error message, if any, or something generic informing the user of the failure.

Don't just assume the email was sent succcesfully.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM