Database change notifications to a windows service? - c#

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 ?

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.

Related

.NET How to Allow a Windows Form Application to be a Webhook Reciever

The current project I'm working on is a Windows Form Application, which in large part functions as a background service to make Queries to a decent number of APIs and store that information into a database. Pretty straightforward.
As I implement more data sources the issue I'm running into is that one of the places I'm pulling from wants to use webhooks to push that data to me. Again fairly straightforward, I did some tutorials on making ASP.NET Web API projects and all of that makes sense in isolation.
Now what I'm confused about is to tie it all together. From my understanding, the options I have would be to have the Form application and the Web API application run separately, which seems like more separation than I want (especially considering that the webhook is for a single item of data that already ties into what the Form application is handling). Alternatively the other option would be to get the Form application to to self host a Web service which seems like the way to go, but I'm unsure of how to approach that without starting with the Web API shell.
I tried reading up on it and this and this seem to solidify that it would definitely be possible to just host the webhook receiver/controller server inside of the form application without making a new project for it. But I'm not sure of what config, new files and settings of that kind it would take.
I would be super thankful for anyone who could offer guidance about how to go about implementing this webhook controller in a project type not designed for it by default, or if you could tell me that it's a bad idea and I should make separate projects for them.
Thank you for your help!
"Webhooks" (or HTTP callbacks, in general) require a publicly routable address. At home, your desktop computer likely sits behind a NAT and with a dynamic IP address, so it won't work unless you enable port-forwarding and find out your publicly routeable address (assuming it's possible at all and you aren't running inside a restricted company or school/university network). You'll probably want to use AWS Lambda or Azure Functions as a quick and simple way of accepting messages from the public web which your desktop program can retrieve them from later-on (using a "mailbox" paradigm). You could try making it work in real-time with a WebSocket or EventSource but I don't know if that works from AWS Lambda or Azure Functions - if it doesn't then you'll need a "real" website.

C# using WCF when sending rows of data from online db to local db to online db

Good day, i have basically no experience in sending information over the internet, so excuse me if this is a little to DUH for you, i am trying to better my understanding.
What i have is a mysql database hosted somewhere on the WWW which is populated with a web application, i also have a local database stored on my ..local machine, which is populated via a windows form created in C#.
All of the above works like a charm.
What happens is, the web site creates some data in ONLINE_TABLE_ORDER.
The local app does some dark magic (based on data in ONLINE_TABLE_ORDER and populates TABLE_1 in the local mysql database, then TABLE_2 stores a bunch of data based on whats going on in TABLE_1.
On the click of a button its time to send ALL the data from TABLE_2 to ONLINE_TABLE_STATS which is the online mysql database and keeps updating the same table for statistical purposes.
What i need to do, is to send the rows of data from ONLINE_TABLE_ORDER to the local database, the C# windows form will then automatically pick up the details and populate various controls, when all is said and done the application will then need to send rows of data from TABLE_2 to ONLINE_TABLE_STATS where the web form will then pick up this new data and display it accordingly.
That being said, i now need to figure out how to go about sending all of this.
This is where WCF and web services comes in.(i guess, its what information i have managed to wring out of google).
Now i would like to do this via services to maintain data integrity (local internet is shitty, and could cut out at anytime, so i am hoping that web services can help with that).
Finally, this is where my understanding needs some TLC,
1: Can a WCF service form part of my C# application; in that the application pulls data from the web based mysql database and then pushes data back to that database?
2: Can a WCF service run by itself from within the local application? or does the server on which the web database is hosted also need a WCF service running?
3: Does only the online server need a WCF service running? (create an applet in C#?)
4: Is this all overkill and i dont actually need any services when a simple bulk insert statement suffice? (remember shitty internet).
Remember, i would like the service to handle
ONLINE_TABLE_ORDER --> TABLE_2 --> ONLINE_TABLE_STATS
No, i am mostly self taught and am really eager to learn more about this, even if it is overkill; as i have been checking out tutorials and blogs, none have actually given me sufficient answers to the above.
Most, deal mainly with application to hosted database but have yet to find one from database to database which is what i am trying to do.
So in closing, if you can help my understanding as well as leave some kick ass links to great reading material, id really appreciate that. If you lovely individuals require anymore information about the how's or why's, leave a comment and ill edit my question.
I think you need to comunicate from your CSharp app to your online database via web services like you said. So, you need a WCF service hosted online with access to the database (or other kind of service, like an api in the online web site who have access to the databse). Also you need a service client in your CSharp app who comunicates with the online server.
So answering to your numbered questions:
A WCF can be hosted in a C# application (called "self hosted service" or something like that) but it does not resolve your problem. Your CSharp app should be client not service.
Basically the same answer than before
The online server need some kind of service who interacts with the database listening to http request. So, WCF is a good alternative. You can use another kind of web service, like a api service in the web application
In MY OPINION i think you need a service who controls security, data transport and a lot of stufs

Windows Azure and Metro-style apps in Windows 8

I have atleast 5 billion ideas for a new App in Windows 8. However, most of them rely on a remote database connection.
Which is currently not possible in Metro apps. But I don't want just a work-around. Or an script that accesses an API which will access the DB and return results. So then I went to the MS forums and found a post somewhere (which I can't seem to find now) stating that I can just use Windows Azure SQL database and can connect to that one from within Windows Metro.
But I don't see any resources or documentation to back that up and I'm completely lost as to what to do.
Most apps these days, to offer any sort of personalized user experience need to communicate with the outside world and it's just impossible to do in Metro apps from what I can see.
Does anybody know if you can connect to a Windows Azure SQL DB from within a Metro style app? Any resources/Docs/Links/Samples you know of?
Thank you!
Metro apps are optimized for tablets and generally CPU-and-battery constrained devices. Directly connecting to a database and processing the results is expensive in CPU, battery AND bandwidth terms.
What's more, database protocols aren't cachable and were not meant to deal with internet latencies. Your app could waste a lot of time trying and retrying to connect to the database each time the connection quality degraded.
The best option would be to a set of WCF Data Services on top of your database and expose them to your application. It's easy to create a WCF Data Service on top of an Entity Framework model and the OData protocol used by WCF Data Services allows querying your entities using LINQ in an asynchronous manner. More complex processing can be done in the web server.
At this point Metro does not have a System.Data so there is no direct connect to the database. You would need to communicate with the database via WCF to a Web Service.
Metro does have a user settings facility but I cannot find it right now. http://msdn.microsoft.com/library/windows/apps/BR208189
The history is that the jumping off point for Metro was Silverlight. Not saying that makes sense just what I have read. It appears Microsoft wants to sandbox Metro for the Metro Store.

Sms Delivery Recived Detection in Windows Application

I'm using the mCore SMS Library. I'd like to create a windows application and when i receive a delivery message, the application should save that information into a database.
What technology can i use?
Can i use windows services? How can i implement a windows service?
I think there are several questions you are asking so let's them split up a little:
How to save delivery information in a Database File
To solve this problem you first need to know what kind of database you have (MS Sql, Oracle, MySql, etc.) For each of these exists some kind of DbAdapter. For e.g. the MS Sql you can take a look into the .net framework System.Data.SqlClient Namespace.
Can i use Windows Services?
This depends on the availability of your application and on what machine it will run. In a first step you can write it as a normal application. To get it later into a service you can take a look at Walkthrough: Creating a Windows Service Application.
These are only very vague answer, but you only asked very vague. So dive in and if you good any concrete problems come back with a new question. ;-)

N-Tier with C#?

I am looking at writing a WinForms app and getting stumped over what seems to be simple issue.
There is a server and database (SQL Server) Open ports are HTTP, HTTPS
There is a WinForms client. It needs to connect a TCP/IP stream (possibly HTTP, SOAP, REST) to the server.
Sometimes the WinForms client goes off-line and then the WinForms client stores its data in a database.
When the WinForms client goes on-line to server, it synchronizes data to the server, gets all the latest data from the server and updates local database.
How do I do that?
Newbie question
As you've conceded, this question shows you might not know where to begin looking for how to architect this kind of application.
I'd start here: http://msdn.microsoft.com/en-us/library/ms973279.aspx
The offline architecture you've described is a little tougher for a newbie than not supporting this, consider making the application only work online first, then add offline functionality.
Also, if you have a web server you will almost always use HTTP, SOAP and REST are strategies that sit on top of HTTP. I cannot recommend that a new developer look at any server communication using direct TCP/IP.
Edit: Answer to related question - there are tons of ORMs and service builders, not a lot of them have built in support for offline workflow but ODX does, but it might be a bit out of date. NHibernate and any of the projects in the Castle Project are very popular components for what you're looking to do also.
No idea how actively this is still being supported by Microsoft, but you might check out the Smart Client Software Factory, it seems to support offline mode and smart reconnecting like you need.
http://msdn.microsoft.com/en-us/library/ff709809.aspx
You could approach this with a 'Service' mindset - Write a WebService (preferably a WCF service) - that forms the synchronization tier between your Winforms app. and remote database.
So, you would have your
1. Local WinformsApp. with a local database (as functional/lightweight as you want it to be)
2. WebService
3. Remote app./DB
Here are some links to tutorials/resources:
http://www.codeproject.com/KB/architecture/three_tier_architecture.aspx
http://services.community.microsoft.com/feeds/feed/query/tag/n-tier/eq/tag/visual%20basic/eq/and/locale/en-us/eq/and
http://msdn.microsoft.com/en-us/library/bb384570.aspx
http://msdn.microsoft.com/en-us/library/bb384398.aspx
IMHO this isn't usually as simple as it may sound
If you were able to go DB to DB, then SQL replication could be the simplest mechanism for synchronisation.
However, since it sounds like you are using a SOA approach, you might need to look at frameworks which have offline support built in, such as the Ent Lib Composite Application Block and Smart Client Software Factory
You might also look at using Queues (e.g. MSMQ) to accomodate network connectivity problems.
Microsoft Sync Framework (http://code.msdn.microsoft.com/sync) + WCF solution here:
http://code.msdn.microsoft.com/sync/Release/ProjectReleases.aspx?ReleaseId=3762
Database synchronisation is not an easy task to get started with, by any means. Good luck.
Generally, you need a local database, or at least a local cache.

Categories

Resources