Friday, 27 September 2013

Using WCF for view service (either with or without using PRISM)

Using WCF for view service (either with or without using PRISM)

Currently we are developing a WPF client which is exposing a WCF service
to receive the request of opening a new report window, by window I mean a
WPF Window with a UserControl we defined. So the initial idea is WCF
generates the UserControl. However, I am having some threading problem of
generating the UserControl:
Since WCF is servicing in a background thread, it is forbidden to generate
a UserControl there. I can work it around by setting the
UseSynchronizationContext to True for the ServiceBehavior. So the service
will be ran on the thread specified by the SynchronizaitonContext, which
in my case is the UI thread. However, there are two questions here.
using SynchronizationContext seems to make it impossible to have a WCF
service with callback (the open new window service doesn't return any
value. But I need some other operation which does), see this:
UseSynchronizationContext=false
I am not sure of executing WCF in UI thread, because it means I must make
extra effort to keep UI responsible (I admit this reason might not be
valid. I don't know, please point out whether it is a good practice).
I know that by using for example PRISM, we can have a view service to
compose ViewModel and View. I mean I can generate a ViewModel in WCF
service and pop it up to the view service (which is executing on UI
thread) to find and generate the corresponding View. But the truth is we
are still hesitating about using PRISM so such view service is not
available at least in the near future.
So I was wondering, what would be a good structure of such a requirement,
i.e., having a WCF to take a request and initialize a new Window hosing a
View?

No comments:

Post a Comment