September, 2012

Scripting Web API self host with Roslyn CTP – Part 1

Because with Roslyn you can do stuff you didn't even dream about

If you follow me on Twitter you probably already know that recently I’ve been playing around with Roslyn. If you don’t know about Roslyn, in very short, you can think of it as “compiler as a service”.

There is a whole plethora of stuff that Roslyn allows us to do, one of the coolest being the scripting API – enabling us to use C# as a script language (think i.e. Perl or Python). So I had this idea, why not script a fully functional web server through Web API self host?

More after the jump.

Continue reading

Dealing with large files in ASP.NET Web API

Because if you are not careful, it's easy to OOM

There are a couple of things to consider when dealing with large file uploads and ASP.NET Web API. First of all, there are typical issues related to hosting within IIS context, and the limitations imposed on the service by default by the ASP.NET framework.

Secondly, there is the usual problem of having to deal with out of memory issues when allowing external parties or users to upload buffered large files. As a consequence, streamed uploads or downloads can greatly improve the scalability of the solutions by eliminating the need for large memory overheads on buffers.

Let’s have a look at how to tackle these issues.

Continue reading

Generate Kindle (MOBI) ebooks with your ASP.NET Web API

Because, it's so crazy, it might work

Recently, I’ve been working a little on an application that allows users to save, tag, bookmark links for later reading – that kind of stuff. Obviously, Web API facilitates those types of apps really well, as data can be exposed in a magnitude of formats. So I had this crazy idea – CLR to Kindle? Why not.

Unfortunately MOBI format (used by Kindle) is not that easy to support from C#, as to my knowledge there is no ready-made DLL port or SDK available. On the other hand, Amazon has created a proprietary tool called Kindlegen, which is a command line tool, and allows you to convert HTML into MOBI. We’ll use that – it’s a hacky solution but it sure is a lot of fun.

Continue reading

Boost up your ASP.NET Web API with MessagePack

Because it's like JSON, only more compact!

A while ago I blogged about supporting BSON at your Web API end points. A good alternative to both JSON and BSON has, for quite a while now, been MessagePack.

The main problem with supporting MessagePack in your Web API has been the fact that MessagePack required a strongly typed serializer (in other words, you needed to tell the serializer what type you serialize and deserialize at compile time). There was no easy way to provide support for boxed objects (untyped context) – and Web API media type formatters run against such generic object instances. In face, to be precise, writing to a stream (serializing) has never been a big problem, but reading was very complicated. An easy solution was a type whitelist and a massive if-else block, but such approaches are hardly good ideas.

Four days ago, Yusuke Fujiwara, one of the wizards behind MessagePack for CLI, added support for untyped serializer factory, effectively inviting all of us to start using MessagePack in Web API.

Continue reading

Using Azure Mobile Services in your web apps through ASP.NET Web API

Because ZUMO is not just for Windows 8

Azure Mobile Services is the latest cool thing in town, and if you haven’t checked it out already I really recommend you do, i.e. in this nice introduction post by Scott Gu. In short, it allows you to save/retrieve data in and out of dynamic tables (think no-schema) directly from the cloud. This makes it a perfect data storage solution for mobile apps, but why not use it in other scenarios as well?

For now Azure Mobile Services (a.k.a. ZUMO) is being advertised for Windows 8 only (the SDK is targeted for Windows 8 applications), but there is no reason why you couldn’t use it elsewhere.

Let’s do that and use Web API as a proxy.

Continue reading