Web API vs ServiceStack

In this blog post I will examine the claim made in a twit by Anil Mujagić. The claim is that ServiceStack is 3 times faster than Web Api. It is backed by test project https://github.com/anilmujagic/ServiceBenchmark. These are the results of that test:


This tool, I've created takes the data of the IP ranges for each country shared by http://www.nirsoft.net/countryip/index.html and stores it in a SQL Server database, so later you can query it.

To use it you need to add App.config file based on included App.config.sample. Add there your connection string to SQL Server database, and the desired table name. Those are the steps the tool executes:

  • Drops the table if exists
  • Creates table and all the required indices
  • Gets the CSV file for each country from http://www.nirsoft.net/
  • Turns the IP records of each CSV file into INSERT SQL statements
  • Executes the inserts into the SQL database

I tried the same code as parallel and sequential to compare performance. The results are as follow:


Here is an open source tool we developed at Move.


You can also find it in Nuget repository https://nuget.org/packages/com.bodurov.DynamicProxy/1.0.0

The tool takes an existing object and wraps it in interface able to implement this object. For example if you would like to wrap HttpRequest in an interface that you can later pass to your business objects and mock in your tests.

This is how you would use it:


My latest work is this Silverlight control for discovering and visualizing the difference between two text files or just two strings that you copy and paste. You can choose files either by clicking on the file buttons and selecting them from the file dialogue or you can just drag and drop them in the boxes.

Demo is available here: http://www.bodurov.com/TextDiff/

Unlike my previous post at http://blog.bodurov.com/Implementing-Longest-Common-Subsequence-Algorithm-in-JavaScript-Text-Diff/ where I just wanted to prove the concept that it is possible to implement the Longest Common Subsequence Algorithm in JavaScript, this app is optimized and capable to handle much bigger strings. It also can work with files.


When we use SqlCommand with a set of parameters, they are being executed as a parametrized query. You may or may not pass the desired type with each SqlParameter. If you do not specify desired database type it will be determined by the ADO provider, but you will not know what the actual SQL type is. Below I provide a code that will give you the actual parameters. This code can also help you find out what the actual SQL query executed in the database is.


We are all familiar with using the embedded code block in the MVC framework views. They give us a powerful way to implement the functionality of the views without removing the separation between code and UI. One of the most common use is for generating UI of different controls through the use of HTML helpers.

But there is one significant limitation of that approach. All the code defined in a common embedded code block will be executed during the render stage of the page execution cycle.

But what if you had the following scenario: you register different css files in different parts of the view. Perhaps in different partial views and then you print them in the header section on top of the page. Something that would look like that:


Source: http://htmlsummarizer.codeplex.com/

This is one C# tool that I want to share. It can be used for extracting a portion of an HTML code without cutting the HTML tags in half or leaving unclosed tags. It also allows to measure the length of the extracted part in number of letters, words, sentences, closed HTML tags, closed P tags, closed DIV tags and closed P or DIV. When counting the number of letters or words, those contained within the HTML tags are not considered.

If you have some content stored as HTML in a database, or if you want to summarize an HTML page residing on a remote server you have to be able to extract a certain number of words or letters without considering the HTML tags them self and without leaving unclosed HTML tags. This is the exact tool for this kind of scenario.


The main idea of the Unity Framework is to give us the ability to quickly replace different parts of big application without having to recompile or re-factor our code. Ideally that means adding another assembly to the bin folder or GAC, and certainly that is the right way to add new providers or class implementations. But sometimes you may want to quickly script a provider in order to test a new idea on your staging server or debug a problem without having to deal with all the hassle of adding a new assembly.

Well, the first idea that comes to my mind is to use a class defined in the App_Code folder. The class will be recompiled each time there is a change in the source file so this seems as a perfect candidate for a quick test. But there is one problem. The assemblies for the classes in App_Code folder are dynamic and so we don't know what their name is, and because of that we cannot set the right class reference in the configuration file.


A common problem for a .NET project is that after deploying a DLL into the bin folder or as a matter of fact doing any change in the bin folder of a web site all the data for any of the current in process sessions is lost. The same happens if we change the web.config file.

In some cases it makes sense to be so, for example if we store in the session objects that are being changed by the current deployment of a new DLL. But in many other cases it is rather a disturbing frustrating side effect that we want to avoid.


If you need to serialize your business objects into XML you may also need to generate automatically XML Schema so you can check the XML against that schema before try to deserialize it. This is one utility that will do that for you. Now, let’s first see one utility that will do basic XML serialization and deserialization objects.


Here I want to describe the steps you can use to search for database performance bottlenecks before you deploy your web application to production server.

1. Modify Fiddler Rules

We want to add to Fiddler the option that would allow us to execute a sequence of requests and then tell it to repeat the same sequence N number of times.

First of all if you don’t have Fiddler yet, install the latest version from http://www.fiddlertool.com/Fiddler2/version.asp then start it and go to Rules - Customize Rules…


Web service proxies for asmx web services are quite annoying. They are supposed to represent the contract between the service and the client and without any doubt there should be such a contract. But in reality they represent not only the contract between the service and the client but also the tool that generates them. And they make you vulnerable to any inefficiencies of that tool. Do you like to be dependant in such a way?

Well, fortunately WCF offers much better approach. The contract between the service and the client is represented by an interface decorated with the right attributes. That is all you need for the contract between the client and the server. There is no third party involved and everything is clear. I like that.

Here is an example of a wrapper around the WCF client.


I want to start adding video tutorials to my blog in order to make it a bit more interesting and fun.

My first video will be a short movie of how to use Flajaxian file uploader. The topics covered in this video are:


Writing unit tests for any application that connects to a database is always challenging, because deviation from the expected alterations of the database may influence the work of the business objects. The same tests have to run over and over again – after each change of the code, in order to ensure that the previous functionality has not been broken by the newly introduced changes. Altering the data so many times may have unpredictable consequences.

One of the most popular solutions of that problem in the Java and .NET worlds is the usage of mocking framework, for example Rhino Mocks. And despite the enormous advantages of this approach it has also some noticeable drawbacks. For example it is not hard to imagine a situation where your tests will pass well with the mocked data but will fail on the real database. And what if you have a lot of business logic in stored procedures that also need to be tested?


Normally when generating Json you would serialize typed .net objects. In most cases this is the right way to go, but if you have important reasons not to use this approach, for example if the format of the coming data cannot be predicted at compile time and you don’t want to generated dynamically typed objects, for performance reasons, you may consider generating Json code as string. A common way to go is to use StringBuilder, but I would not call it as a very json friendly tool, so here is an alternative.

Json builder can help you iterate through collections and hide json related string transformations from you. Here is how you use it:


This is a simple tool for traversing the file system in search for a file or folder or doing something to many files.

The source is available here: http://www.bodurov.com/files/FileSystemIterator.zip

And here is a sample application that searches for the first file with extension .aspx


Another Flajaxian.com tool is the adapter that you can use together with Flajaxian FileUploader, the tool is FREE and open. You can use it to enable file upload to a CS3 Amazon Service.

Flajaxian S3 Amazon Service Uploader is adapter for the Flajaxian FileUploader .NET web control designed for asynchronous file upload to an Amazon Service of multiple files at the same time, without a page post back and with a progress bar indicating the current upload progress. This control and adapter do not require full trust environment.

For download and documentation, please go to: http://www.codeplex.com/FlajaxianS3Upload

The web site is: http://www.Flajaxian.com

You can see a Wiki page here: http://flajaxian.com/flajaxian.com/docs/html/HowToUseAmazonUploader.htm


I would like to present one project I am starting together with a friend – Flajaxian.com. This is a web site providing FREE, open source tools for AJAX web development.

The first tool you can find there is .NET web control for AJAX style file upload designed for asynchronous file upload of multiple files at the same time, without a page post back and with a progress bar indicating the current upload progress. This control does not require full trust environment. The control can be extended with the addition of server side and client side adapters. Flajaxian FileUploader uses Adobe Flash Player 8 or higher Flash player for the file upload.

For download and documentation, please go to: http://www.codeplex.com/FlajaxianFileUpload

The web site is: http://www.Flajaxian.com


Please note that the advantage of Hashtable over generic Dictionary for insert and search operations demonstrated here is actually because the tests are based on NON generic IDictionary interface, so each insert or search action is accompanied with check for the key type. For more information see the Sean's comment below. (Thanks Sean!) Without that Dictionary seem to perform better than the Hashtable. The rest of the test conclusions will not be affected. So to summarize, generic Dictionary is the absolute winner for insert and search operations if used with generic dictionary interface or directly.

This is a sequence of tests comparing the performance results for four different implementations of IDictionary and in particular generic Dictionary, generic SortedDictionary, the old non-generic Hashtable and generic SortedList.


This is a very simple but useful application for viewing the sequence of bytes or bits in a binary file. I have modified my old bytes viewer and added the option to view the sequence of bits as well.

You can choose the start and end index of the bytes / bits being viewed.

This is how the application looks:

The application also supports dragging and dropping files into the form.

You can use it together with Fiddler by selecting a session and then choosing for example File - Save - Request - Request Body.... Then open it with the bytes viewer to view the sequence of bits and not only bytes as it is in HexView of Fiddler.

The source:


And the executable (requires .NET 2.0 installed):


Here is a simple example of how to create a web proxy for a flash file.

Flash has many restrictions for files loaded from a different domain. When you don't have any control over the flash file located on a remote server, a solution might be the creation of a web proxy like the following one:


Here I would like to share some of the tools I've developed.


This is a class for viewing the stack trace. You can use it as:
if you want to have the stcktrace as file, or
if you want to have it as string.

The class: