Realtime updates between C# desktop app, mobile app and SQL server - c#

Can anyone explain the best practice communication flow for a multi-app solution I am currently working on. I will have a MS SQL server database running. This database will be accessed and updated by one or more windows desktop applications and mobile devices(android, iOS and Windows). Whenever any changes are made to the database, the clients should be updated in real time to reflect. The desktop applications are most important and need to be updated with as little delay as possible. The mobile apps on the other hand can tolerate a delay of a minute or so.
My idea is connect the desktop application to the server using signalR, the database will then notify any connected clients of the update via SQLDependency. For the mobile side, I was planning for the server to send notifications to the mobile devices, where upon receipt of the notification, the mobile device would requery the SQL Server (via web service) to update itself.
I guess my question is, is this the best (standard) way to go about this or is there a better/quicker/more robust way to achieve this.
Any advice would be appreciated.

I would suggest you create an API in C# and host in on IIS. Your desktop app (be it web or native) will then use RESTful calls to the APIs.
The API's, hosted on IIS would communicate to SQL Server. For database operations, you would have CRUD (Create, Read, Update, Delete). You would expose a GUID (generated using NEWID() in sql server) to each CRUD method and supply serialized data. E.g. perhaps XML or JSON POSTed to the API.
In my view (and practice), this is the Best option. It is truly global, and the API's can "talk" to any client app capable of making HTTP requests.
So the system becomes:
SQL Server > API/IIS > Client (Android, iOS, JS, Java, Windows, Unix, Mac, etc)
Benefits here also are:
SSL out of the box
RESTful transactions - can use oAuth or write your own (proprietary is harder to hack!)
Highly scalable - IIS support 100's of transactions per second
Do not need to open port 1433 (SQL port) to web (which will open you to hacking). API uses port 443 (HTTPS)
If you write your API using C#, you have many serialze/deserialize functions out of the box.
Hope this answers your question.

Related

How to limit access to Azure Function App to a website and clients only

I have an API running on a Function App in Azure.
I want this API to only accept communications from two parties:
A blazor website
All copies of a piece of packaged software (a WPF application which will run on customer computers)
I want all other traffic to be rejected.
What is the best way to configure this networking scenario?
The ideal setup:
API should only be able to talk to the Blazor App as well as the client programs, not outside connections. The API can talk to the database which lays behind a virtual network. This Database VNET is already set up.
Any help is appreciated.
Use API Management in front of the API and require Ocp-Apim-Subscription-Key in the requests.
Also, add ip restrictions to avoid unauthorized access

Communication between a server and unity app

I'm developing an android game using unity. I have a pi-server (static ip, port forwarding, apache 2, php, mysql and phpmyadmin all set up) and I want to use it to store scores from my app to it as well as retrieve top scores for a leader-board. What code should I use to facilitate the kind of communication I want? To be more precise how would I send through the sql code to the server and read the data?
It is the first time I'm attempting to do this kind of thing, so sorry if it is something obvious. Other info: port 80 is set for forwarding, the database is called "game_scores", table is called "highscore" and the table consists of 4 columns: id, username, score and date.
Although it's possible to have your app communicate directly with the MySQL database on your server (through port 3306, not port 80), the standard way to facilitate this kind of connection is to instead implement a web service (REST API) that runs on your server, listens for HTTP requests from your Unity app, and connects to the database to respond to your app with the data it needs. Communicating with your server through HTTP (or similar protocols) creates an abstraction layer that allows you to change or swap out your server or database implementation in the future without changing the client. Here's a decent-looking tutorial that describes how to create a simple REST API with PHP and MySQL. Once you create the REST API on your server, you can send requests to it from Unity using UnityWebRequest.

Two-way Communication between Server and Clients

Situation: We have a web application running on a server. This application needs to fetch data from some other PC(Clients), which are on a different network.
On the clients' pc there are WCF hosted in Windows Services using its their local Sql db. i want to make duplex communication between server and clients for share data with each other.
data share mean share data-table,data-set,string etc between clients and server .
Problem :
1) I have no control over the firewall, proxy, NAT on the client side PC. Mostly company Employee PCs have lots of network security e.g firewall block ICMP traffic and some port too, some Router might be Disabled port-forwarding etc etc , client can change network place.
I don't want to make any setting on client side Router,proxy,firewall though .
during communication how can i handle that's kind of issue of client side?
as you know skype is working perfect in that situation.
firewalls very often block inbound connections to clients; the client may not be reachable from the server, it may be using NAT translation behind a router and so cannot be contacted without port forwarding being set up on the router and some new router disabled port forwarding .
2) On clients side there is no IIS .
I don't want to allow remote access on clients PC.
There are more than 100 Clients and only one Server. one server need communicate with many clients on different network .
3) One side my client application is using window application and wcf hosted in window service ,Other side on my server i'm using Web application . so its mean communication is between desktop pc and web pc , that's issue .
If both using a web application then it was not issue to make duplex communication.because i know WEBRTC is fit there lol.
Technology which i had already test and find issue
WSDualHttpBinding: Not work if client behind NAT. check this for detail click here
MSMQ : its bad technique if clients more than 1 and performance issue also because its use RAM memory . check here click here
Xsocket: Its also not work if ICMP traffic block by firewall on client. check here click
WebRTC: Its work fine but its support web to web communication .as my client side i have win app.
Socket.io: Its need to set up node.js and many other thing , hard to implement because i need implement on existence application , i am not making new application.
C# Socket Program: Its wouldn't work if client behind NAT.check here click for detail
Service Bus relay: Its not free even for testing .
socketPro: I studied i find its good but i can't find any right sample on google .so that i could test that.
Genuine Channels: I can't find any sample on google .
Lets see SignalR issue .: Server side i run a console application and Client side i run two application ,one is console and other web. when i was running console client application than it was not initiating connection with Server but when i was using web client application then it was working fine.
sample link is here SignalR two way communication
I can't understand why thas??
Please tell me What is best most secure and fast way to handle this situation? what approach should i use ?
SignalR seems to fit for this solution, because it's flexible.
It negotiates the fastest available channel of communication and that is what you are looking for.
You should investigate the problem with it and signalR will eventually work.
I'm using SignalR extensively to communicate between the servers (C#), between server and mobile apps (C#, Xamarin, iOS, Android). The servers are at different locations and the mobile apps can be anywhere. It all works very reliable.
Take a look at: http://www.asp.net/signalr/overview/deployment/tutorial-signalr-self-host and here http://www.asp.net/signalr/overview/guide-to-the-api/hubs-api-guide-net-client
I've been working in my spare time with sockets (admittedly in c++, not c# but there shouldn't be a difference), and I've never had an issue connecting to clients behind a firewall/router, even without port forwarding.
Routers and firewalls generally don't like server-like programs, eg. programs that bind the socket to a port number. Does your client do anything related to binding? Because it shouldn't.
Needless to say, I would suggest a socket program. The way I see it, it's the most flexible way.

Socket programming to control the number of clients

I m developing a C# database application. I used SQL Server 2005 as back end and C# .NET 2010 as front end.
My application is installed on each client machine. When database is updated all clients of my system get notified By SQL Server Event Dependency technique.
But now I want to control the number of clients connected to server. That is I only want to give access to 3 clients. For that, I want to add some client/Server code in my application using socket programming.
Please guide me on this issue.
From the SqlDependency Class on MSDN:
SqlDependency was designed to be used in ASP.NET or middle-tier services where there is a relatively small number of servers having dependencies active against the database. It was not designed for use in client applications, where hundreds or thousands of client computers would have SqlDependency objects set up for a single database server. If you are developing an application where you need reliable sub-second notifications when data changes, review the sections Planning an Efficient Query Notifications Strategy and Alternatives to Query Notifications in the Planning for Notifications topic in SQL Server Books Online.
In your particular scenario, I guess it would be a good idea to have a middle layer server which manages the client machines and which will use the SQLDependency to be notified by the changes in the database. Then, it will push notifications to batches of n client machines, following the logic you expect.

Best solution on building a Client server app

I run and play with c # and wonder how I can create a client server solution that can exchange information.
I have created a program that reads and transmits data to a USB device.
What I want is to create client applications that can talk to this server application and receive information when there is data from USB and can send back data to the USB.
It is a kind of client-server solution. Where I have support for WPF app, and in the future could create www pages that can display the status icons from the USB device.
The question is in essence how this should be made?
WCF services / web services / TCP Stack (client server solution)
I need an event trigger when it comes USB data so that clients do not need to ask all the time if there is new data. Is this posible in a web service?
The question is in essence how this should be made? WCF services / web services / TCP Stack
(client server solution)
Depends. The only sensible answer is "by programming". Web Services are mostly out (WCF does waht they do and more - the old web service implementation is basically an outdated old implementation.
But besides that it totally depends. I have an app here that needs to transport 100.000 data items per econd as fast as possible - no web service could do that. I have some that require web services.
WCF is possibly a good start, but you should learn all the technologies and then coose according to explicit needs.

Categories