C#


10
Oct 10

Using RabbitMQ with C# and .NET

I’m currently working on a project where I need to be able to transfer a large number of requests via JSON over web services. I need to take some of that data, do some aggregation with it, and store it in a persistent store. In order to allow the data to be reliably processed in a number of different ways, I wanted to place the incoming data into multiple queues and have it processed and then stored. Something like this:image

At this point you might be wondering why I’m not using MSMQ, since most of the work I do is on Windows. Well, a few different reasons. First and foremost, I am running all of my infrastructure inside of EC2, so I want the option of running the queues on a Linux box. Secondly, because the web service front end is a very thin layer that simply transforms the incoming JSON into message to drop on a queue, I want the option to run those in whatever language I want and be confident that I will have no issues connecting to the queues. Third, I want to be able to persist or not persist messages to disk and have my queues operate entirely in memory or on disk. This is especially useful in EC2 where hard disk performance is somewhat lacking.

Continue reading →


13
Sep 10

Classes Are Not Objects

I was reading a blog post by Derick Bailey last night and I got into the comments due to a few tweets that I saw (I’m on Twitter if you want to follow me). It was a lot of noise and ranting, but one topic that came up was that people working in languages such as C# and Java quite often mistake classes for objects. Working in a language like C# they can feel quite similar, since the distinction is merely that a class represents the abstraction of a set of objects, while an object is just an instance of a class. You can think of the class as the cookie cutter and the object is the cookie.

So what is the importance of this distinction? Well, in C# prior to 4 the distinction wasn’t very important. You didn’t really have a good way of interacting with a class in a way that the class definition didn’t provide. In C# 4 the dynamic type was introduced along with a late binding mechanism that allows the object to respond to methods which don’t exist on the class definition. So, are they really method calls at all? We aren’t actually calling a method, right? This is exactly why many languages will talk about message passing rather than calling methods.

Continue reading →


17
Aug 10

WCF Web Services The Easy Way

I’m gonna go ahead and say it… I don’t think WCF is all that bad. In fact, I think it can be pretty easy! I hear lots of complaints about it, and many of them valid, but by far the biggest complaint I hear is that it is just so darn difficult. Especially cause of all that xml configuration. Holy crap I hate XML configuration! (If you want to complain some more, I’m on Twitter) And because it is perceived as difficult, it is often overlooked in favor of ASMX web services because they "just work".

While normally I would be the first in line to use a tool that "just works", in this case I think that WCF is carrying around baggage of its earlier incarnations. I want to show you that as of .NET 3.5, WCF can be just as easy for setting up web services as ASMX, and that you no longer need to fear it. Or fear the day that Microsoft deprecates ASMX web services.

Continue reading →


22
Jun 10

C# Closures Explained

Thanks to all of the functional goodness that was put into C# 3.0 we have a ton of power at our disposal. Unfortunately with a lot of this power also comes increased complexity. Programmers usually exacerbate the complexity problem, because unfortunately we often like to sound like we are smarter than we actually are.

We often like to use big words and lots of acronyms to scare away the neophytes. Oh crap, there I go again…

Anyways, one of these topics that is blindingly simple is closures. But I continue to see definitions that are as clear as mud to the average developer. Let’s go ahead and look at the Wikipedia definition of a closure:

“In computer science, a closure is a first-class function with free variables that are bound in the lexical environment.”

All clear, right? Well, if it is for you, then super… you can stop reading. But if not, and the next time this topic comes up you want to sound like Super Duper Computer Science Guy™ … then keep reading.

Continue reading →


12
Apr 10

Easy And Safe Model Binding In ASP.NET MVC

A little over a year ago (wow, it seems like only yesterday), I made a post called Think Before You Bind. In this post, I presented to you exactly why you want to make sure that when you are doing automatic binding to models in ASP.NET MVC, you need to absolutely make sure that you are only binding to the properties that you expect. The reason for this, is that in ASP.NET MVC you really have no way of telling what was supposed to be posted to the server, and what wasn’t, so someone could tamper with, or create fake, post data and overwrite properties that you weren’t expecting to be changed.

This isn’t something unexpected, but it is definitely not something that Web Forms developers have to really consider when building their solutions. On the flip side though, ASP.NET tracks what fields are supposed to be on the form which ties you into a fairly static number of fields, unless you want to hack your way around that model. And I think many of us know how ugly that can get…

Continue reading →