C# – Two way Communication between Server and Clients

asp.netchttphttpswebsockets

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.

MSMQ : its bad technique if clients more than 1 and performance issue also because its use RAM memory .

Xsocket: Its also not work if ICMP traffic block by firewall on client.

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 not work if client and sever on different network .

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 which i get.: 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. 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 ?

Thanks Advance .

Best Answer

This can be done using a WCF CallBack contract.

If the client can make a connection to the server, the server can use a WCF service with a callback construction. This describes that the server expects the client to implement a service as well (the callback service), as part of the service contract.

This beaks down as follows:

  1. The server hosts a WCF service.

  2. The service contract has a CallBackContract attribute:

    [ServiceContract(CallbackContract = typeof(IMyServiceCallback))]

  3. Clients that want to use this service, must implement the desired callback contract (service) to be able to communicate with the server.

  4. When a client connect with the server side service, the reverse / callback connection will be made over the same connection.

Using callbacks is done over the same connection (that has already been opened). This requires a two-way communication channel (for example http).

See http://adamprescott.net/2012/08/15/a-simple-wcf-service-callback-example/ for an example how to implement this.

Related Topic