将数据从 Web 应用程序提交到 C# 控制台应用程序

发布于 2024-07-13 11:26:29 字数 365 浏览 7 评论 0原文

我需要将数据从 Web 应用程序提交到控制台应用程序。 当前计划要求 Web 应用程序将数据提交到数据库,并要求控制台应用程序轮询数据库,然后在插入数据时对数据进行操作。 我是否应该更改控制台应用程序以包含 Web 应用程序可以提交数据的 http 处理程序,这样就不必轮询数据库? 有没有更好的方法在这两个应用程序之间进行数据通信? 控制台应用程序永远不需要将数据发送到网络应用程序。

更新

这是一个 .NET 2.0 控制台应用程序,因此 WCF 似乎不是一个可行的选择。 数据有效负载相当小(几个 9 位 ID 字段,总共不到 150 个字节),并且将以每分钟约 10 个的速率发送。 这两个应用程序之间没有防火墙。

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.

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

沫雨熙 2024-07-20 11:26:29

我不确定您的要求或设置,但 WCF 可以是一个选择。

[编辑]
要进行扩展,您可以在控制台应用程序中托管一个 wcf 服务,并让 asp.net 站点调用它。 就此而言,远程处理(或任何其他形式)也可以发挥作用。 这样,在不需要时,您就不必让控制台应用程序池化数据库。

I'm not sure of your requirements, or setup but WCF could be an option.

[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.

吻泪 2024-07-20 11:26:29

使用最简单的技术,您的控制台应用程序可以在由计时器或后台工作人员控制的循环中连接到数据库。 您需要一种方法来了解哪些记录是新的,哪些不是。 如果您在轮询时可以从该表中删除记录,则意味着每次执行此操作时,您只会获得新记录。 如果无法删除它们,请使用该表中的时间戳字段,每次轮询时都会选择该时间戳大于上一批的最大时间戳的记录。 如果您需要将这些记录标记为已处理,那么您可以设置该标志并忘记时间戳。

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.

老子叫无熙 2024-07-20 11:26:29

您基本上想要一个应用程序到应用程序的通信。
有很多选项,但实际上取决于您的要求(数据量、大小、频率、延迟)、环境(防火墙后面、在线/离线、恢复)等。

使用数据库是一种解决方案。 但您可以使用其他的 - 例如 Web 服务 (wcf)、消息传递系统 (msmq)、甚至 .net 远程处理。

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.

Using a Database is one solution. But you could use others - like webservice (wcf), messaging system(msmq), .net remoting even.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文