Saturday, December 1, 2012

How can a portable class library not have a common http client?

Visual Studio 2012 has introduced a concept called a Portable Class Library. In theory this should allow us to write assemblies to target multiple platforms such as Windows Store apps, the Xbox, and Windows phone; reusing as much code as possible. This should leave us to only need to write platform specific code as it relates to the particulars of the UI of each of those systems.

What is odd, and what in my mind renders the whole concept almost irrelevant is that there is not an http client library shared across the major platform targets. I don't know about your code but the aside from maybe some serialization POCO types, maybe a sprinkle of business logic and perhaps some MVVM stuff, the important and complex things that need to be shared across platforms is accessing http services.

I find that supporting diverse REST services, their peculiarities and differences of authentication and authorization to be the most tedious part of writing device apps and therefore the most valuable candidate for abstraction in a class library.

But as far as I can tell if you make a PCL that targets store apps and windows phone apps you have to implement platform specific extension points to govern http access.

Silverlight and Windows phone get's the WebClient; store apps the HttpClient. I have no idea what the Xbox needs. Without a cross platform http abstraction I can't really see making much use of a PCL and will likely resort to linking source files across project types or conditional compilation directives.