简体   繁体   English

从Asp.net向Window Service发送消息?

[英]Send a message to Window Service From Asp.net?

I have a scenario where I have a window service running. 我有一个正在运行窗口服务的场景。 Whenever, a specific exception occurs in my asp.net web, I call window service or send a message to my window service from asp.net web and window service generates an email on receiving that message. 每当我的asp.net网站中发生特定异常时,我都会调用窗口服务或从asp.net网站向我的窗口服务发送消息,并且窗口服务会在收到该消息时生成电子邮件。 What would be the best best solution for this scenario. 对于这种情况,什么是最好的最佳解决方案。 Should I use some kind of wcf service or shared database. 我应该使用某种WCF服务还是共享数据库。 Please guide me in this regard. 请在这方面指导我。

Your requirement is very similar the way Messaging happens using MSMQ. 您的要求与使用MSMQ进行消息传递的方式非常相似。 You need a shared place where you can post the exception from your asp.net and it will be picked by the Service. 您需要一个共享的地方,您可以在该地方从asp.net发布例外,该例外将由服务选择。 There are different options available . 有不同的选择。 One of them is using MSMQ where you can post the data to the queue and your service can read it. 其中之一是使用MSMQ,您可以在其中将数据发布到队列中,而服务可以读取它。 If you are interested in installing MSMQ and its coding aspect . 如果您有兴趣安装MSMQ及其编码方面。 Database will be the best solution. 数据库将是最好的解决方案。 Have a table where you can log the exception message with all the information . 有一个表,您可以在其中记录所有信息的异常消息。 Now your service will pick the records and process it and mark it as complete. 现在,您的服务将选择记录并进行处理并将其标记为完成。 You can have two way of doing it, either after processing Delete the record , this will make your database very light and fast to work with. 您可以采用两种方法,一种是在处理Delete记录之后,这将使您的数据库非常轻便并且可以快速使用。 Other approach will be to keep a flag , with status like POSTED , PROCESSING and COMPLETED . 其他方法是保留一个标志,其状态为POSTED,PROCESSING和COMPLETED。 I am using the same way in my current PHP project but you can have C# way also where I am using mongoDB , NoSQL : https://github.com/gaillard/mongo-queue-csharp . 我在当前的PHP项目中使用相同的方式,但是在使用mongoDB,NoSQL的地方也可以使用C#方式: https : //github.com/gaillard/mongo-queue-csharp Directly posting to WCF will not be a good idea in case some error happens in between , you will loose the message for ever. 如果在两者之间发生错误,直接将消息发布到WCF并不是一个好主意,您将永远放下消息。

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

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