JohnC1
JohnC1

Reputation: 861

Communication between ASP MVC and WinForm Applications

I am looking for a way user can communicate between an ASP and Winform applications.

I am looking for something like soluto.com, I want to let the user send commands to other computers via Website. So let's say the user signed up for 10 computers, which is registered on the mvc app. User can select all the 10 computer and send a "Do this task" with a click of a button.

I am thinking something like, Winform will create a httplisten server. Everytime winform is open, it will send a "I am online" post to mvc, along with IP:Port. The server will send a request to that ip:port when required.

That approach seems very unsecure though, having an open port, configuring firewall and etc, seems like a overkill.

I was wondering if there way any other way of accomplishing this.

Thank you for the help.

P.S. Before you claim this is a stupid idea, Piriform is doing something like this also. Take a look at Agomo.com

Upvotes: 4

Views: 2366

Answers (3)

Trevor Elliott
Trevor Elliott

Reputation: 11252

Why don't you just have the Winforms app use a standard HttpClient or WebRequest to periodically poll the service (maybe every 5 seconds or so) and ask if there if there are any tasks that need to be performed?

Unless you need realtime, low-latency, high performance communication then this is the easiest way to solve your problem with minimal to zero client side setup or security configuration.

The way I would do it is implement it like a stack in a data persistence layer. So each client could have rows in a table that are added when a task is queued. When the clients sends an HTTP GET request to the MVC server it will return the an array of tasks for that client and you could have it either delete them from the database right away or wait for the client to send a HTTP command later to indicate which tasks it completed.

You could represent tasks as a simple data object with a few properties, or just a string or int that you can lookup on the client in some way to invoke the appropriate code.

For reasonable security each client just needs to be given a unique key like a GUID or equivalent that it can later send to the server to validate its identity. This is also known as a cookie, secret, or API key.

Upvotes: 0

John S.
John S.

Reputation: 2007

Use SingalR with properly architected web and windows applications (e.g. MVP, MVC, etc.)

SignalR with window client (WPF)

Console App & SignalR

Upvotes: 4

Moho
Moho

Reputation: 16553

Create a WCF service within the WinForm application, specify endpoint(s) (and secure the endpoint appropriately), and connect to said endpoints from your ASP.NET application the same way you would also connect to a WCF service.

Upvotes: 0

Related Questions