Category Archives: C#

WCF Duplex Reentrant Services

Introduction

This article illustrates working with Duplex mode in WCF with concurrency set to Reentrant. In general, Duplex is one of the three message exchange patterns (MEPs) which are:

  • One-way
  • Request-Response (synchronous and asynchronous)
  • Duplex

On the other hand, concurrency in WCF services deals with how many concurrent threads can access these services at one time.

A full discussion of MEPs and Concurrency in WCF is not the intent of this article; as a matter of fact, that would be the job of a full book. As such, this article assumes familiarity (but necessarily experience) of the following:

  • WCF programming
  • MEPs in WCF
  • Concurrency modes in WCF
  • Basic concepts of threads

Continue reading

C# 4.0 Optional and Named Parameters

C# 4.0 now supports the optional and named prameters. this feature was already there in VB.NET so it is a C# language enhancement.
consider the below class:

class Optional
{
public void DoOperation(string name = “hello”, int age = 4)
{
Console.Write(“Name {0}, Age {1}”, name, age.ToString());
}
}
Continue reading

C# 4.0 Dynamic

one of the core functionalities of .NET 4.0 is its support for Dynamic languages. this is done primarly through the Dynamic Language Runtime (DLR) on top of the CLR. this post shows some of the usages of dynamic in C# 4.0.

consider the following class:
public class Sample
{
public static int Add(int x, int y)
{
return x + y;
}
Continue reading

Cool C# Code

i was reviewing a piece of code of a colleague, and i came across a very familiar pattern of code. basically he had a list of employees where he wanted to “loop” over and exclude any employees with age over 30. so his first attempt was the most common one: he used a foreach loop to remove all employees with age > 30. the code looked like the following

foreach (Employee empl in lst)
{
if (empl.age > 30)
lst.Remove(empl);
}
Continue reading