7

I am using WebAPI to push some data in to the database.

A windows service operating in the same server has to get notified when a data is inserted by the WebAPI

I have seen this SO question which suggests using Service Broker or SqlDependency but the question seems to be asked quite a while ago.

I googled out but could not find any simpler solutions. All I wanna do is when a new data is inserted to Database, a function in the the windows service should fire.

Do we have any alternatives or a much similar solution in WebAPI - Windows Services context ?

Community
  • 1
  • 1
  • Can the Windows Service simply poll the data for changes at regular intervals? Simply looking for records in a given state? – David Sep 22 '14 at 13:01
  • 1
    @David: Actually, it is going to be `time-critical`. So, `polling` does not seem to be a good alternative. – now he who must not be named. Sep 22 '14 at 13:03
  • Ah, in that case it does seem that `SqlDependency` is likely the way to go. Unfortunately I've never used it, so I can't advise on the specifics. – David Sep 22 '14 at 13:05
  • 3
    SqlDependency/QueryNotifications provides low-latency without continuous polling. Under the covers, it does a blocking receive of notifications and periodically repeats after a timeout. – Dan Guzman Sep 22 '14 at 13:06
  • Do you have the source code of both programs ? In this case you can use [Memory Mapped File](http://blogs.msdn.com/b/salvapatuel/archive/2009/06/08/working-with-memory-mapped-files-in-net-4.aspx) – Max Sep 22 '14 at 13:22

1 Answers1

0

There is a way. I don't like it very much, but you can use CLR Integration.
You can use it to write a trigger: https://msdn.microsoft.com/en-us/library/ms131045.aspx

It can contact external resources setting the correct permissions: https://msdn.microsoft.com/en-us/library/ms345101.aspx

Then you can call your service via socket, or make it a webservice. But you need c# programming skills.

user_0
  • 3,173
  • 20
  • 33