简体   繁体   English

与外部服务ASP.NET MVC同步

[英]Synchronization with external services ASP.NET MVC

We want to synchronize the data in our application with the data of an external service. 我们希望将应用程序中的数据与外部服务的数据同步。 (Such as accountancy software. This synchronization should be executed every night and when the customer wants to. (例如会计软件。这种同步应该在每晚和客户想要的时候执行。

I am aware that long running threads don't belong in web applications and this synchronization should be executed within an external windows service. 我知道长时间运行的线程不属于Web应用程序,并且此同步应该在外部Windows服务中执行。 But the downside of this method is, that is becomes harder to deploy / maintain, since the application can be installed on the customer's webserver too. 但是这种方法的缺点是,部署/维护变得更加困难,因为应用程序也可以安装在客户的Web服务器上。

Is it possible to completely integrate this synchronization with just the use of a class library project withing my solution, which will start up at the Application_Start event? 是否可以将此同步与仅使用我的解决方案的类库项目完全集成,该解决方案将在Application_Start事件中启动?

Since your application is hosted on IIS, it's maintained by the application pool process. 由于您的应用程序托管在IIS上,因此它由应用程序池进程维护。 If you create additional module for your task, it will be running within context of the same process. 如果为任务创建其他模块,它将在同一进程的上下文中运行。 You have to be sure this process is still working in the middle of the night, when application is not used, in order to perform the synchronization you want. 为了执行所需的同步,您必须确保此过程在半夜仍在使用应用程序时仍在工作。 You can use Quartz.NET to schedule your sync task. 您可以使用Quartz.NET来安排同步任务。

But still, I think much better idea is to perform the synchronization from windows service. 但是,我认为更好的想法是从Windows服务执行同步。 Service should communicate with the application for example by using database, where it logs its current activity. 服务应该与应用程序通信,例如使用数据库,它记录当前活动。 It gives you the possibility to monitor of the service state from the web by connecting to such database. 它使您可以通过连接到此类数据库来监视Web上的服务状态。 I know service forces some additional administration effort, but it will be much more reliable and secure. 我知道服务会增加一些额外的管理工作,但它会更加可靠和安全。 You can also add service starting possibility from your web application (if pool process user has access rights to windows service) to overcome (or at least minimize) administration effort connecting with restarting your service after some failure. 您还可以从Web应用程序添加服务启动可能性(如果池进程用户具有对Windows服务的访问权限),以克服(或至少最小化)管理工作,并在发生故障后重新启动服务。

I've written such functionality, so just to give you an overall look of what I mean by web monitoring of such external service, check the screen below. 我已经编写了这样的功能,所以只是为了让您全面了解我对这种外部服务的Web监控的意思,请查看下面的屏幕。 It can be written with the ajax support to achieve more responsiveness ( pooling mechanism ), which will be convenient for the end user. 它可以用ajax支持编写,以实现更高的响应性( 池化机制 ),这对最终用户来说很方便。

在此输入图像描述

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

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