UCWA and fun with .NET/Mono

I had some time to take a break from working on JavaScript/HTML and decided to revisit .NET languages to gauge how difficult it would be to create a basic UCWA application. My initial thoughts were to create a simple Console application to ignore UI and focus on how to UCWA in a .NET. This proceeded to balloon into creating a set of helper classes mimicking the JavaScript version, creating a WPF version of the Console application, and finally creating a version that would work on my PS Vita.

Console.WriteLine("UCWA are you out there?");

It did not take long until I had felt I was writing too many BeginX/EndX code that I should consider writing up a few helper classes, combined with Program.cs ballooning out of control. I chose Json.NET as the library with which I would process the response body (mostly due to the list of framework support which becomes important when I attempted to bring UCWA to PS Vita).

Transport was the first helper class to work on as I originally wanted to start AutoDiscovery, but lacked the means to send requests (without duplicating some Transport code of course). The JavaScript Transport library was an adequate starting point as the .NET equivalent should be able to take in a set of request data (url, Http method, Headers, and data) and in turn execute a web request returning a set of response data (HttpWebResponse, Json, and raw data). Transport contained the basics of executing a request, setting authorization credentials (Bearer cwt=xxx), basic request validation, and checking for domain changes (xframe in response Json).

This early in development I was not considering sharing source to enable older frameworks resulting in a fair amount of specialized web request code, but it was sufficient enough for me to attempt replicating AutoDiscovery. Without the need to inject an xframe for cross-domain communication I was able to boil AutoDiscovery down to requesting lyncdiscoverinternal followed by lyncdiscover when needed.

With how easy I found AutoDiscovery I had high hopes that Authentication. Authentication is a bit odd in that the application needs to make a failed request to get the location of the authentication service and use that to get the credentials to make a successful request. In other words Make auth request -> read WWW-Authenticate response header -> Make request to OAuth service -> Make auth request. It was at this point that I neglected to url encode part of my Json response when creating an application resulting in a failure. After rectifying that and making a request to makeMeAvailable I had successfully created a UCWA application using .NET.

At this point I should have considered the concept proven, but I wanted to see something simple like meDashboard replicated on the Console:

The crowning achievement for me was option #7 where I get the photo and display it on the commandline via Ascii:

I did run into one fun issue as a result of using Fiddler so heavily during testing in that when I went to demo it without Fiddler running I would occasionally run into issues where a request would appear to hang. It was after a few searches that I came across: Help! Running Fiddler Fixes My App??? and had to add some clean up code for streams, requests, and responses resulting in a much happier Console application.

WPF and remembering how to data bind properly

With a bit of extra time I decided to tackle a WPF application and attempt to consolidate the helper classes into a helper library. With the helper library in place (aptly named UCWA.Sharp as it was written in C#, but thinking about it now it could have been UCWA.NET...) it was time to re-learn data binding and Mvvm. I do not feel much changed in the helper classes beyond experimenting with creating Batch and Events classes, but I did not reach a point where they became necessary. I took the time to implement a meDashboard and Contacts which included searching for contacts. I did have a bit of fun and tried styling it similar to the samples site included in the helper libraries with some effect. I'd say I was a bit ambitious to put most of the tasks in place with a post for Call Via Work:

PS Vita and struggling against the PS Mobile SDK

I've had a PS Vita for awhile now and rather recently the cost of the license to publish applications has been removed. The PS Mobile SDK (found at PSM Dev Portal) is based on Mono using C# and provides a brand-enhanced (or however you want to think of it) version of Mono-Develop. I created a fork on my helper libraries as I knew I would be making changes to accommodate Mono which resulted in the mass exodus of async/await to be replaced with wrapping most methods in Task.Factory.StartNew(...) among other minor changes.

I did run into the situation that I need to use Json.net, but there really is not a version built for PS Mobile SDK and as far as I could manage it would not let me just pull .NET built version into my project and run with it. Not to be detoured too long I decided to use the source and create a library built against the supplied version on Mono. After much trimming I had a version that would work with application I built using the PS Mobile SDK.

With changes and Json.net in place I attempted to run AutoDiscovery as that should be the simplest bit of UCWA, but I noticed I was failing each request (internal/external). Reading about the exception it seemed that I was having certificate failure in that the PS Vita did not want to accept the certificates presented. With a bit of looking I found that I could correct it by using the ServicePointManager and providing a ServerCertificateValidationCallback. As this was a proof of concept I went with a rather blunt solution:

[code language="javascript" collapse="true"] ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; [/code]

With the fix in place I was seeing the responses I was looking hoping for and so I began to work with PS Mobile SDK's provided UIComposer to create WinForm-like interfaces for logging in and displaying a meDashboard-like contact card. After composing and including the layouts into my project I was able to make changes to the class and add appropriate handlers similar to WinForms. I did have some assets for default user image and presence indicators that had to be included in the output to get them to display properly.

It would not be complete without a demo of it actually running on a PS Vita. In the demo I was changing the user's presence/note via both the PS Vita and Lync Client: UCWA & PS Vita

And that's all folks

For now the proof of concepts will continue to live on my desktop and have time to figure out what to do with a .NET UCWA helper library. It proved (to me at least) that UCWA is not just a technology that can be used in web-based applications.