I need to submit data from a web application to console application. The current plan calls for the web app to submit data to the database and the console app to poll the database then act on the data when it is inserted. Should I change the console app to include an http handler that the web app can submit data so it doesn't have to poll the database? Is there a better way to communicate data between these two applications? The console app never has to send data to the web app.
我需要将Web应用程序中的数据提交到控制台应用程序。当前计划要求Web应用程序将数据提交到数据库和控制台应用程序以轮询数据库,然后在插入数据时对其进行操作。我是否应该更改控制台应用程序以包含Web应用程序可以提交数据的http处理程序,以便它不必轮询数据库?有没有更好的方法在这两个应用程序之间传递数据?控制台应用程序永远不必将数据发送到Web应用程序。
Update
This is a .NET 2.0 console application so WCF doesn't seem like a viable option. The data payload is fairly small (a few 9 digit ID fields, less than 150 bytes total), and will be sent with a rate of about 10 per minute. There is no firewall between these two applications.
这是一个.NET 2.0控制台应用程序,因此WCF似乎不是一个可行的选择。数据有效负载相当小(几个9位ID字段,总共少于150个字节),并且将以每分钟大约10个的速率发送。这两个应用程序之间没有防火墙。
3 个解决方案
#1
Using the simplest technologies, your Console App could connect to the database in a loop controlled by a Timer or a BackgroundWorker. You would need a way to know what records are new and which aren't. If you can delete the records from that table when you poll them, it means each time you do it, you'll get only new records. If you can't delete them, use a TimeStamp field in that table and each time you poll you select the records with that time stamp greater than the maximum time stamp of the previous batch. If you need to mark those records as processed, then you can set that flag and forget about the timestamp.
使用最简单的技术,您的控制台应用程序可以在由Timer或BackgroundWorker控制的循环中连接到数据库。您需要一种方法来了解哪些记录是新的,哪些不是。如果您在轮询它们时可以从该表中删除记录,则表示每次执行该记录时,您将只获得新记录。如果您无法删除它们,请在该表中使用TimeStamp字段,并在每次轮询时选择该时间戳大于上一批的最大时间戳的记录。如果您需要将这些记录标记为已处理,那么您可以设置该标志并忘记时间戳。
#2
I'm not sure of your requirements, or setup but WCF could be an option.
我不确定您的要求或设置,但WCF可能是一个选项。
[edit]
To expand, you could host a wcf service in the console app, and have the asp.net site call it. For that matter, remoting (or any other form) could work as well. This way you wouldn't have to have the console app pool the database when not necessary.
[edit]要扩展,你可以在控制台应用程序中托管一个wcf服务,并让asp.net网站调用它。就此而言,远程处理(或任何其他形式)也可以起作用。这样,在没有必要时,您不必将控制台应用程序池合并到数据库中。
#3
You basically want an app to app communication. There are a lot of options, but really depend on your requirement (how much data, how big, how often, latency), environment (behind firewall, online/offline, recovery) and so on.
你基本上想要一个app应用程序通信。有很多选择,但实际上取决于您的要求(数据量,数量,频率,延迟),环境(防火墙后,在线/离线,恢复)等等。
Using a Database is one solution. But you could use others - like webservice (wcf), messaging system(msmq), .net remoting even.
使用数据库是一种解决方案。但你可以使用其他人 - 比如webservice(wcf),消息系统(msmq),甚至.net远程处理。
#1
Using the simplest technologies, your Console App could connect to the database in a loop controlled by a Timer or a BackgroundWorker. You would need a way to know what records are new and which aren't. If you can delete the records from that table when you poll them, it means each time you do it, you'll get only new records. If you can't delete them, use a TimeStamp field in that table and each time you poll you select the records with that time stamp greater than the maximum time stamp of the previous batch. If you need to mark those records as processed, then you can set that flag and forget about the timestamp.
使用最简单的技术,您的控制台应用程序可以在由Timer或BackgroundWorker控制的循环中连接到数据库。您需要一种方法来了解哪些记录是新的,哪些不是。如果您在轮询它们时可以从该表中删除记录,则表示每次执行该记录时,您将只获得新记录。如果您无法删除它们,请在该表中使用TimeStamp字段,并在每次轮询时选择该时间戳大于上一批的最大时间戳的记录。如果您需要将这些记录标记为已处理,那么您可以设置该标志并忘记时间戳。
#2
I'm not sure of your requirements, or setup but WCF could be an option.
我不确定您的要求或设置,但WCF可能是一个选项。
[edit]
To expand, you could host a wcf service in the console app, and have the asp.net site call it. For that matter, remoting (or any other form) could work as well. This way you wouldn't have to have the console app pool the database when not necessary.
[edit]要扩展,你可以在控制台应用程序中托管一个wcf服务,并让asp.net网站调用它。就此而言,远程处理(或任何其他形式)也可以起作用。这样,在没有必要时,您不必将控制台应用程序池合并到数据库中。
#3
You basically want an app to app communication. There are a lot of options, but really depend on your requirement (how much data, how big, how often, latency), environment (behind firewall, online/offline, recovery) and so on.
你基本上想要一个app应用程序通信。有很多选择,但实际上取决于您的要求(数据量,数量,频率,延迟),环境(防火墙后,在线/离线,恢复)等等。
Using a Database is one solution. But you could use others - like webservice (wcf), messaging system(msmq), .net remoting even.
使用数据库是一种解决方案。但你可以使用其他人 - 比如webservice(wcf),消息系统(msmq),甚至.net远程处理。