简体   繁体   中英

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. What would be the best best solution for this scenario. Should I use some kind of wcf service or shared database. Please guide me in this regard.

Your requirement is very similar the way Messaging happens using MSMQ. You need a shared place where you can post the exception from your asp.net and it will be picked by the Service. 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. If you are interested in installing MSMQ and its coding aspect . 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. Other approach will be to keep a flag , with status like POSTED , PROCESSING and 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 . Directly posting to WCF will not be a good idea in case some error happens in between , you will loose the message for ever.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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