Array instead of List in WCF

This article describes the differences between using arrays and generic lists in WCF.

Introduction

Recently, I was developing a function which included transferring an image in a message package. So, following a habit, I made up a property in the message class like this: public List<byte> Image { get; set; }. This Image is sent to the client through a duplex channel. Can you imagine how I was surprised when I saw the percentage of processor consumption for this service process? It was ~15-20% loaded with an image size of ~400 KB. I then started to think about a better solution.

Using the Code

A search for a solution to the problem took a considerable quantity of my time, and then, having replaced the type List<byte> with an array of bytes, I received considerably better results: practically ~1-2% loading. Why is there such a big difference between what would seem like identical types of data? The difference is in how the SOAP message is generated. For List<byte>:

Points of Interest

In general, the difference in size of these two SOAP messages differed approximately 10 times, and the loading of the processor fell from ~15-20 % to ~1-3 % at the same size of package. I was very surprised, because nowhere have I found official information on these differences.

I see, but i am not using the wrong construction. MTOM firstly used to prevent base64 expenses, and for example for WS bindings it is analogue and ,i think, better solution, but not for non base64 formatters (for example netTcpBinding, where i had found this problem firstly) In this article i had no purpose to show difference between list and array and what they inherits. I just wanted to show the way to FIND firstly this strange problem and then solve it in SIMPLE and working way, as many guys don't know, that lists and arrays in WCF have different results in performance.

.45 ACP - because shooting twice is just silly-----"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997-----"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001