Monday, May 5, 2008

Creating a CWA client with Silverlight 2 beta1 (part 1).

I was wondering if it was possible to create a silverlight application that would function as a CWA client. After some research, I found out that it can be done. In this series I will show you how it can be done and what problems I had to overcome to get it working.

Ideally, you would build a silverlight application that would run in any web application. At the moment this can’t be done.
Silverlight does support cross-domain access but only under certain circumstances:
•    only with http connections no https yet.
•    In root of the Target server there has to be a XML file that

allows silverlight to access that server from another domain(the CWA isapi catches all requests so that is a problem, you can create an extra isapi filter that only serves that xml file).
Therefore, building a Silverlight application and having the possibility to debug has to be done on a CWA server directly. Create a visual studio 2008 web application that actually runs directly on a CWA server.

image

After having overcome the problem of debugging, the next problem popped up: Authenticating.

Using the AJAX sdk there are several ways to authenticate (forms authentication, Integrated authentication). They all use a http-header(CWA-Ticket) after you have been authenticated.
After you logon to the server, you get your CWA-Ticket in the response headers, which you need for all further requests. Now we have a problem.

In silverlight the System.Net.HttpWebResponse doesn’t have any headers. How do we get that CWA-Ticket after logging in? We need that CWA-Ticket for all requests were going to make.
There is a solution for this problem, we have to use the browsers XMLHttpRequest object. I don’t wanted to use this object all the time. For now, I only get synchronous requests to work. So for commands and logging in I use the XMLHttpRequest for the asynchronous calls(asyncdatachannel) I use the System.Net.HttpWebRequest.

I know some people would say Silverlight does support Multithreading so that is not a problem. That is what I thought also. But actually the HttpWebRequest and XMLHttpRequest(ScribtObject) can only run in the UI thread. You do not want synchronous calls in your UI thread (it can block your client).

Here is a code sample to create the external XMLHttpRequest:

image

In part 2 I’m going to explain how to actually logon and initiate the session. Please contact Marc Wetters @
Sip:Marc.Wetters@e-office.com or send him an email on Marc.Wetters@e-office.com . Enjoy and please feel free to give us your feedback.

No comments: