Thursday, April 10, 2008

WPF in web

I’m recently working on a project where we come up with a
decision to use wpf in web. The main reason behind taking this decision is we
want to share some component already developed in desktop using wfp and our
company we have some suit of products always can be share some module both web
and desktop. Previously we need to develop a lots component with same feature
for web and desktop. Huhh no more redundant work should come up a common
platform. After some basic r&d we jump to develop some share module for
both desktop and web using wfp. We are smoothly going with wfp in desktop but
in each step in web we fall one by one problem (in bangle “minca chipa”).

I’m short out some problem that not too much context
specific and anybody want use wfp in web most frequently fall on those issues.
Here some of those

1. Hosting xbap on aspx pages.

We are decide to use some component are sheared both web and
desktop so we are choose hosting xbap inside aspx page rather then root
application is xbap though it’s possible to call aspx pages from xbap using
ifame.

Here is example how to html in xbap. Carefully looks on
source that’s a bit different in case of xbap.

<Frame
Source="pack://siteoforigin:,,,/example.aspx" Width="Auto"
Height="Auto" MinHeight="600" MinWidth="1024"
></Frame>

But we don’t want to lose basic web programming model for
just using xbap also we has already implemented authentication and other
functionality using asp.net. If xbap become root application it will be nothing
but a smart client. So we hosting xbap inside aspx page using iframe

<iframe id="xbap"
src="../EmbadedObjects/UIContainer.xbap?SessionID=mnwlgu2lzvcyfm45z4hixs45&ComponentID=Organiger"
/>

At the beginning we are expecting may be there must be some
way to communicate with java script from xbap and vise versa very basic web
developer expectation huhhh. And start getting disappointed from beginning
there is no way to communicate java script and xbap. Ohh noooo can we read at
least Query string and cookie from xbap?? Hmm yes we can

Here is code

//how to Query string from xbap

BrowserInteropHelper.Source.Query.ToString();

//cookie from xbap

Application.SetCookie(new Uri("http://nahid2.kaz.com.bd/servicedep/WpfBrowserApplication1.xbap"),
"Hellllo");

Application.GetCookie(new
Uri("http://nahid2.kaz.com.bd/servicedep/WpfBrowserApplication1.xbap");

Important things to say about Query string in you will get
the Iframe source as query string not from url you see in browser address bar
if your host using iframe.

Ok hosting is complete now we want to talk with server from
xbap. wcf obviously good option and get another problem while using wcf from
xbap

You can easily use basicHttpBinding binding but we need
session so we need wsHttpBinding but we are getting System.Web.Security
exception

And we find out the way how to call wcf with wsHttpBinding
we need to do reliable session off and security none. Here is the configuration


<wsHttpBinding>

<binding name="WsHttpBindingNoSecurity">

<security mode="None" />

<reliableSession enabled="false" />

</binding>

</wsHttpBinding>

<service name="Service.Service">

<clear />

<endpoint
address="http://localhost/ServiceHost/Service.svc"

binding="wsHttpBinding"
bindingConfiguration="WsHttpBindingNoSecurity"

contract="Service.Service"
listenUriMode="Explicit" />

</service>



To be Continue

2 comments:

Eugene said...

Hi Nahid,
I am trying to solve the same kind of problems in my current project as you mentioned in your post. I am a little bit confused by some explanations in your post. You wrote that you had to go with wsHttpBinding because I needed sessions support. But once you set reliableSession enabled="false" you won't get any sessions anymore! So, question is: have you managed to use sessions with XBAP application?

Thanks,
Eugene

Nahid said...

Hi Eugene,
Well, if you see my recent post(http://nahidulkibria.blogspot.com/2008/05/how-to-run-wfpxbap-in-full-trust-mode.html) we are move to full trust mode so we can use reliableSession now!
I hope you are not confused with service SessionMode enable and reliableSession, we are not going to use (SessionMode = SessionMode.Allowed) because of concurrency issue. Our project we write a SessionManager that obviously static class and push session item on that. If you not clear yet let me know.