How to call console application inWeb API?
Loading
How to call console application inWeb API?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Pasang TamangPosted Jan 13, 2023, 4:27 PM
Hi,
Btw, is there any specific reason you want to execute console application from Web API? If it is related with some background processing then better you run it using windows task scheduler. You can read more about executing console app using windows task scheduler in this article https://www.c-sharpcorner.com/UploadFile/manas1/console-application-using-windows-scheduler/.
Regards,
Pasang
Sachin SinghPosted Jan 13, 2023, 2:17 PM
If you want to start the console app from web api then follow @Pasang Tamang answer .
If you have made some methods in your console app and want to resuse those methods inside your web api then cut the methods from console app's program class and paste them inside a class within a separate class library project so that you can call those methods from console app as well as web app or web api.
Sujay AnandPosted Jan 13, 2023, 12:40 PM
I want to call the console application inside WebAPI
Sachin SinghPosted Jan 13, 2023, 12:19 PM
First, let me know the purpose of it?
Do you want to start any service thorough console app ? Basically for self hosted scenario we start web api from console app and not console app from web api.
so, first let us know the reason behind that so that we can assist better.
Vishal YelvePosted Jan 13, 2023, 10:44 AM
Is your question right ? or Do you want to consuming web api in console app.?
if you want to consume web api inside consile app please refer
https://www.c-sharpcorner.com/article/creating-web-api-and-consuming-in-console-application-using-web-client-in-a-sync/
Pasang TamangPosted Jan 13, 2023, 10:39 AM
Hi,
If you want to execute console app from your Web API then you can use System.Diagnostics.Process. Check below code. Make sure you have console app and Web API project hosted in same machine.
Regards,
Pasang