Is it possible to convert a WinForm to a WebForm in .NET?

I didn’t think it was possible but I was just talking to a co-worker who said she had done it before. Is she pulling my chain?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

It’s not something you can do automatically.

The trick is both Winforms and Webforms represent a form using a plain old class. However, instances of the class in Webforms are short-lived compared to Winforms; each Webforms class instance represents only one HTTP request, rather than the entire lifetime of the form, as with Winforms. Every time you handle an event for your form in ASP.Net Webforms you’re working with a brand new instance of the class. Microsoft went to a lot of trouble to try cover for this issue as much as possible, but in the end it’s just not a good idea to think of a Webform in the same terms as a Winform.

You can definitely take a Winforms app and rewrite it to use Webforms, but it will be just that: a rewrite.

Method 2

Yes, it is possible. If you have designed the application well enough it should be relatively easy to convert a Win Forms application to a web forms application by just swapping out the UI layer and replacing it. You are re-using the logic and data layers (which is where all the functionality would be).

Obviously, you have to write a new UI layer from scratch, but, if the logic layer is written well enough that isn’t going to be too much work compared with writing the whole application again from scratch.

However, there are some gotchas even if you have a very well written application. The logic layer may assume a stateful application in which case it may rely on lazy loading. In a web application you have a stateless model which is run on requests and responses. In that scenario you’d know exactly what you need up front and can load just the bits you need and not other things that may be needed later on… because later on will be a different request/response cycle and all the data you collect now is going to be dropped as soon as the current response is completed.

I’ve recently been putting the logic of an application that was originally a WinForms into MVC and the biggest barrier to getting a responsive speed is the fact that, although reasonably well written, the logic layer assumed a stateful environment. The same application is being also re-written for WPF (another stateful environment) without so many issues.

Method 3

Converting a desktop application to a web application has several challenges:

  • Access to hardware
  • Windows API calls
  • Management of the application state
  • Access to the file system
  • Access control
  • Use of desktop-specific UI/UX/controls

There are options to convert desktop applications in an automated way, these can convert both the UI and the code of the application:

Even when using automated migration tools, in most of the cases you will have to perform a significant amount of manual work to get the application working in the same way as the original one.

Some of these tools will help with different objectives, the first one will help you convert only the UI and to WebForms, the last two ones will generate ASP.NET MVC, one using a custom runtime and set of libraries and the other with common HTML/JS/CSS libraries such as Kendo MVVM, Kendo UI, AngularJS or Bootstrap among others.
These tools will provide a solution that will be faster than writing the application in the web from scratch and will provide solutions or at least guidelines to approach the challenges mentioned before. However, there will be some differences from an application that was designed for the Web, simply because the architectures are different and usually the way of writing the code for a desktop application assumes thing that cannot be assumed for a web one.

Disclaimer: I work for Mobilize.Net, who built WebMAP.

Method 4

Adding to previous answers, please note that there is some winform functionality that simply doesn’t exist in a webform so it depends on exactly what’s in the winform in the first place.

Method 5

just a comment more: the rewrite depends of how much logic is in the form itself. With properly separated concerns, it is only a matter of plugging in another UI onto the business layer.

The problem is, offcourse, that 90% of apps isn’t anything more that somewhat complex CRUD UI’s (no real business logic)…


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x