In this post I will add references to other pages which do a great work on explaining how to use this approach to host a Windows Forms App inside a WebBrowser.
The technique described here is a deployment solution to ease distribution of applications modernized from legacy technologies to Windows Forms, maybe using the Artinsoft\Mobilize.NET tools ;)
NOTE: "This workaround of .NET Winforms to WPF and then hosting it in a browser isn't truly moving a Windows based application to a web based application. e.g. database calls will be made from inside the browser on the users PC to the database, not via the IIS server. Therefore this functionality is most useful if you have connected your Winforms UI to you back-end code using web services, then you can have a somewhat web based application."
Adam Berent gives step by step instrutions:
Figure 1: Example of Windows Forms applications running inside FireFox browser using an XBAP wrapper.
Some details that are missing in this article are related to how to publish the application on IIS, and these can described as:
1. Create a test Certificate within Visual Studio and sign it against the project.
The following links provides information on how to sing the xbap with your own certificate.
2. Within VS publish the application.
4. Install the certificate on the Client PCs
The certificate must be added in the trusted publisher and in the trusted root authority. If this is not done correctly you get the error 'Trust not granted'
"In the past, Web developers often used ActiveX controls to provide rich client-side functionality in their Web applications. Now developers can easily build objects using the Microsoft .NET Framework that are more compact, lightweight, secure and can be hosted within Internet Explorer. By hosting .NET Windows Forms controls in Internet Explorer, developers can accomplish many client-side Web development goals..."
This is an excellent introduction from Thiru Thangarathinam article in CodeGuru
In the rest of this article he provides great details on how to accomplish this task.
Figure 1: Example of simple Hello Word Windows Forms App embedded in Browser
Figure 2: Example of a more complex Windows Forms App consuming data from a Web Service
" However before using Windows Forms controls in IE, you need to be aware of the benefits and limitations. The main benefits include:
-
The ability to deliver dynamic rich user experience through the Web
-
Automatic caching of compiled code on the client
-
Seamless integration with .NET Code Access Security that allows you to leverage the .NET security model from within the client side
-
Improved performance over Java applets
-
It requires Windows operating system on the client side
-
Internet Explorer 6.0-9.0 is the only browser that provides support for this type of hosting
-
It requires .NET runtime to be installed on the client machine.
-
It also requires Windows 2000 and IIS 5.0 or above on the server side"
Recently we added some support for migrating the IsMissing function to VB.NEt or C#
The thing is. In VB6 the IsMissing Function is TRUE only if you have something like:
Public Sub Foo(Optional str)
Where you dont specify the variable type, or if you have
Public Sub Foo(Optional str as Variant)
And is IsMissing is FALSE for any other case. Including Optional variables whose definition type is not Variant.
So let's see some examples to illustrate the idea:
Example 1:
Public Sub Foo(str, a As Integer, b As Integer, Optional c As Integer)
MsgBox (str & "Foo Is missing a " & IsMissing(a))
MsgBox (str & "Foo Is missing b " & IsMissing(b))
MsgBox (str & "Foo Is missing c " & IsMissing(c))
End Sub
It occurs that IsMissing is really FALSE in all cases. So it is equivalent to:
Public Sub Foo(str, a As Integer, b As Integer, Optional c As Integer)
MsgBox (str & "Foo Is missing a " & false)
MsgBox (str & "Foo Is missing b " & false)
MsgBox (str & "Foo Is missing c " & false)
End Sub
Example 2:
Public Sub Goo(str, a As Integer, b As Integer, Optional c As Object, Optional d As Byte, Optional e)
MsgBox (str & "Goo Is missing a" & IsMissing(a))
MsgBox (str & "Goo Is missing b" & IsMissing(b))
MsgBox (str & "Goo Is missing c" & IsMissing(c))
MsgBox (str & "Goo Is missing d" & IsMissing(d))
MsgBox (str & "Goo Is missing e" & IsMissing(e))
End Sub
All cases EXCEPT "e" are equivalent to FALSE
Public Sub Goo(str, a As Integer, b As Integer, Optional c As Object, Optional d As Byte, Optional e)
MsgBox (str & "Goo Is missing a" & false)
MsgBox (str & "Goo Is missing b" & false)
MsgBox (str & "Goo Is missing c" &false)
MsgBox (str & "Goo Is missing d" & false)
MsgBox (str & "Goo Is missing e" & IsMissing(e))
End Sub
So if you are migrating your VB6 Code to C# put attention to these little details it can save you a lot of time.And remember that this is just one feature of VBCompanion tool ;)