Sign in to follow this  
BTownTKD

[.net] Exposing a WPF/MVVM Application To A Web/(Silverlight) UI

Recommended Posts

BTownTKD    205
I have a WPF application which I've structured using the MVVM design pattern. I would eventually like to extend the application in such a way that it will listen on an HTTP port, and allow remote users to make modifications via a Silverlight client. In order to accomplish this, I have a number of unknowns:

1) Are there any built-in .NET classes which I can use to easily instantiate a "server" object in the WPF application, in order to listen for HTTP requests?
2) Would there be any special steps required, to host a silverlight application from inside my WPF executable?
3) The end goal would be to have any changes made in the Silverlight interface automatically appear in the WPF user interface - I would ideally like to accomplish this by sharing the ViewModel objects between both the Silverlight and WPF Views, but I'm not sure if that is possible (would there be binary compatibility issues?).

Thanks in advance for your thoughts,

-Brian

Share this post


Link to post
Share on other sites
ChaosEngine    5185
Depending on the level of complexity, you might be better refactoring the model part of as a web service that both front ends access.

There are a couple of options you could look at also.
[list][*]XBAP, kinda heavy weight as a web client, but involves the least work on your part (assuming you don't need full trust)[*]refactor the entire app as silver light and use out of browser on the desktop[/list]
To answer your questions:
1) Not sure, but as I said this is generally done by writing a web service rather than hosting a web server in your wpf app
2) You can host your silverlight content in a [url="http://msdn.microsoft.com/en-us/library/system.windows.controls.webbrowser.aspx"]WPF WebBrowser control[/url], but I'm not sure about communicating with the content (i.e. calling methods on your silverlight classes)
3) You can share code between WPF and silverlight, but it's not easy. Silverlight runs on a different CLR to "regular" .net apps. You can share the code files by adding them as links in two seperate projects (one silverlight, one wpf) but that you will need to be careful to only use code that silverlight supports.

TBH, it's a bit of a pig. The silverlight restrictions can seem kinda arbitrary (for instance, [url="http://msdn.microsoft.com/en-us/library/zkcaxw5y.aspx"]this overload of string.compare[/url] isn't in silverlight, despite just being a forwarding call to [url="http://msdn.microsoft.com/en-us/library/e6883c06%28v=VS.95%29.aspx"]this overload[/url]). Last time I tried it, I found it near impossible to reuse xaml across the two platforms, mostly due to namespace inconsistencies. In short you can do it, but you'll end up hamstringing your wpf interface to work with silverlight so much that you'll either keep the UXs separate or just using one.

Best of luck.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this