简体   繁体   English

将C#控制台应用程序连接到Web API以更新数据库

[英]Connecting C# Console Application to a Web API to Update DB

I am really new to the concept of RESTful Web APIs, please do not go hard on me but I just really cannot think a way of it. 我对RESTful Web API的概念真的很陌生,请不要强加于我,但我真的想不出办法。

So basically, what I cannot find a solution for that I cannot find a way to make my console application works without my manuel 'start' command so that DB can stay up to date so that in the meanwhile API would only be responsible for getting the data from DB or other CRUD operations. 因此,基本上,我找不到解决方案,无法找到一种方法,无需使用manuel'start'命令就可以使控制台应用程序正常工作,从而使DB可以保持最新状态,因此,API仅负责获取来自数据库或其他CRUD操作的数据。

I had a console application which can parse data from a website and store the necessary values to the database. 我有一个控制台应用程序,可以解析网站中的数据并将必要的值存储到数据库中。 Then in the same solution, I also created a Web API - MVC project and wrote CRUD operations for all entity data types. 然后,在同一解决方案中,我还创建了一个Web API-MVC项目,并为所有实体数据类型编写了CRUD操作。 They both works without any problem, however unless I manually make the console application to run the code and update the DB, DB has old values so the get operations ended up with wrong values. 它们都可以正常工作,但是,除非我手动使控制台应用程序运行以运行代码并更新数据库,否则数据库具有旧值,因此get操作最终会得到错误值。

All I wanted to do is to somehow run the console application's code (might be at certain times) so that the DB can stay up to date. 我要做的就是以某种方式运行控制台应用程序的代码(可能在某些时候),以便数据库可以保持最新状态。

Hope I did not ask in a confusing but if I do it is because I cannot figure it out and cannot understand the process. 希望我没有提出令人困惑的要求,但我是否这样做是因为我无法弄清楚它,也无法理解该过程。

Appreciate if someone can briefly explain me what I have to do. 感谢有人可以简要地向我解释我该怎么做。

Thanks ! 谢谢 !

What you're asking really isn't a programming question per se, but more of a scheduling question. 您实际上要问的不是编程问题,而是更多的调度问题。 You could turn your code into a service and install it, but that is really overkill for what you need. 您可以将代码转换为服务并进行安装,但这对于您所需的内容实在是太过分了。 (Some people would argue that a windows service isn't appropriate for this since all it does is run at scheduled times and not wait to intercept information, but that is a whole other discussion). (有些人会认为Windows服务不适合此操作,因为它所做的全部工作都是在计划的时间运行,而不是等待拦截信息,但这是另外一回事。)

What you need is a Scheduled Task in Windows: http://windows.microsoft.com/en-US/windows/schedule-task#1TC=windows-7 您需要的是Windows中的预定任务: http : //windows.microsoft.com/zh-CN/windows/schedule-task#1TC=windows-7

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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