I have a .Net (c#) application with a WinForms GUI. Besides that, I want to provide a secondary web GUI so the application can be controlled from another pc at the home of the user.
So part of the webpages (the values) should be filled in by the application.
The web interface should work out of the box, so no installation or configuration of third party software by the user.
What would be the best way to implement this?
And a second question: Once this is implemented, and I want to run my application on a server and provide access to multiple users on the internet, can I easily move to a more performant web server?
Here are some approaches you could take:
You could use a lightweight web framework like Nancy to serve the pages and have it get data from your application/database. Nancy was designed to run anywhere, which makes it more suited to building a desktop app. You can get a feel for Nancy syntax by reading Why use NancyFx.
Asp.net is usually used with IIS but it is possible to deploy as a desktop application. This Lunar Frog blog post describes how you might go about this. It mentions IIS Express which will need to be installed on your users machine using the official installer.
If you haven't done much web app development it may be best to follow an Asp.net Tutorial and build a dummy app first.
I've not used either myself. Asp.net is the first choice for most C# devs, and will help you learn about structuring a web app well. (REST, Controllers, Templates/Views etc.) But a lighter solution will help you get started quicker and may be more suitable for a desktop app.
Both options can be run on a separate server, but be careful to de-couple your business logic and database lookups from your two front ends (Gui and web). Nancy even claims to run on linux!
You will also need to decide between rendering data into a template, or using javascript to fetch the data.
Both Asp.net and Nancy have their own preferred view engines like NHaml or TextTemplatingFilePreprocessor. Nancy describes the ones it supports here.
Alternatively you could build an API which returns JSON, and use a front end javascript framework like Ember.js, Knockout.js or Angular.js to use that data.
Web API ( http://www.asp.net/web-api ) can accomplish everything you need here.
Ideally (and in most cases) your WinForms app should back all its data to a database (preferrably through the API), and your Web Api will interact with the database, not the WinForms app.
Yes, you can move Web API to other servers in the future.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With