Enable Trace for WCF Service


Recently while working on a WCF service I received an error which said “The underlying connection was closed: The connection was closed unexpectedly”. This error was occurring while trying to execute the service method from the client. My initial thoughts were that it could be a security issue. After doing some goggling I found that it could be due to serialization issues.

Possible causes for this error

Many of the articles and blogs suggested that this can occur if we are using Enum in our service and this enum is transferred to the client as part of data contract. We did have couple of enums defined in our service layer and they were getting transferred to the client. To resolve the serialization issue with Enum we need to decorate the Enum class with DataContract attribute. Also each enum member needs to be decorated with EnumMember attribute. We already had this in place for our service.
It could also occur if there is mismatch in the way collections are handled between the service proxy and the service layer. The generic lists seem to have problems while serializing and deserializing. Matevz Gacnik explains  in his blog WCF: Passing Collections Through Service Boundaries, Why and How , how we can change the default ArrayList to GenericCollection type while transferring data from service to the client.
I tried debugging the service code by invoking the service method using the WCF test client utility. The method was executing as expected on the service side. And the error message was very generic. I needed a way to find out what was happening behind the scenes. That is when I came to know that we can enable tracing in WCF service. This is similar to ASP.NET Page  Tracing feature. By enabling the trace we can get to know the sequence of events what occur on the service side.

How to enable trace for WCF service

One thing I like the most about WCF is the extensibility it offers to developers. Without making any code changes we can enable many things using configurations. Tracing is not enabled by default. In order to enable trace we need to add the following code to WCF Web.config file
            <source name="System.ServiceModel"
                    switchValue="Information, ActivityTracing"
               <add name="traceListener"
                   initializeData= "c:\log\Traces.svclog" />
The level details that gets logged in the output file (C:\log\Traces.svclog) depends on the value of switchValue. The permissible values are
  • Warning
  • ActivityTracing
  • Information
  • Verbose
I have used the XMLWriteTraceListener. Out of the box we also get to choose from other trace listeners which include
  • TextWriterTraceListener
  • ConsoleTraceListener
  • EventLogTraceListener
  • DelimitedListTraceListener
These trace listeners are not just limited to WCF services, but can be used with any type of DotNet application. You can read more about trace listeners on MSDN.


The trace feature was really helpful in identifying the problem I was facing. It turned out that there was a problem with the domain object that we were using within the service. We use NHibernate as ORM for our data access. We needed to set the IsReference attribute on one of the domain object. If it was not for the trace feature it would have taken me long time to resolve this issue. We can add multiple trace listeners for a trace source. That means we can write the same information as an XML as well as a comma delimited file. Or we could write the same information to different sources like a flat file and event log. If required we can create a custom trace listener if the available ones does not suffice our requirement.
Until next time Happy Programming :)

Social networking and developer community


Over the past few years there has been a spurt in the social networking sites. I have received many request from various friends to join their preferred social networking forum. So far I have joined some of them like Orkut, Twitter, Facebook, Linkedin. Prior to these social networking sites people had to rely on various community sites and user groups. I have been part of ASP.NET community and also some of the yahoo groups and user group like BDotNet. Each of these have their pros and cons. I am just trying to summarize my thoughts about the impact of social networking as it stands today on the developer community.

Impact of social networking on developer community

As developers we need to constantly keep ourselves updated with various tools and technologies. The rate at which technology stack is getting upgraded is very fast compared to previous 2 decades. I would say people who were developing software in the 80’s and 90’s had very little choice. There were very few programming languages to choose from. May be C and C++ were frontline languages. There were very few books to refer to and the internet hadn’t taken it off so much.
I think starting with 90’s it all started to change. Lot of information started getting published on the internet and many new programming languages were introduced. Since the millennium the pace at which frameworks are getting introduced is frenetic. Who would have imagined that Microsoft will release  DotNet frameworks 1, 1.1, 2.0, 3.5 and 4.0 all in space of 10 years. Which means about 1 framework every 2 years.

How I try to keep up with fast paced changes

Few years back I used to bookmark my favorites in the browser. But this became a maintenance headache as the number of links and their categories increased. Also when I had to change the machine or in worst cases change the job I had to backup my favorites and zip them to my personal mail accounts. Following are some of the techniques I have used personally to keep upbeat with ever changing technology :-

1. RSS Reader

With RSS came a set of RSS readers. I found Google Reader to be very useful to keep up with the latest blog posts from the various experts in the preferred technologies. Still the problem was that after I had finished reading the blog post, there was very little I could do to preserve it for further reading as a bookmark. I used to email those posts to myself until I stumbled upon Delicious.

2. Online Bookmarking Service

Delicious is an online bookmarking service. The best part I like about this service is the tagging feature which allows us to give various tags for each link that we bookmark. Now I don’t have to worry about my browser favorites.

3. Micro-blogging

Many of the famous bloggers all over the world have taken to the Micro- blogging in big way. It is not like they have changed loyalties and started Micro-blogging. But its the simplicity of one of the most commonly used micro-blogging site Twitter which fascinates almost everybody who uses it. The fact that the content of a Tweet is limited to 140 characters makes it very simple to use. Instead of somebody writing a paragraph about what they found interesting, twitter can be used to provide same information in a very concise manner. Apart from the limited characters in tweets, I also like the tinyurl facility. I have seen many times url which are embedded in emails which are very lengthy spanning across multiple lines. Some of the email clients like outlook have problems rendering these contents at times because of the way lines are interpreted in outlook.
You can shrink the whole url into a tiny bit and send it as a normal link. The tag cloud feature is another plus point of Twitter. We can easily annotate our tweets with a # symbol and a tag which can help while searching for specific category of tweets. For E.g. we can tweet a good link about ASP.NET MVC and annotate it with #ASPNETMVC. If you like something which was shared with you by one of the person you follow and you wish to share it with other, you can use the concept of re-tweet which sends the same message to all the people who follow you in twitter.
Although I find it irritating at times when people start tweeting about minutest things in their personal life like going to bathroom, just out of bed, having coffee etc. But most importantly from a developer point of view i have found some of the best links over tweets and re-tweets. Thanks to the guy who invented Twitter for such a wonderful concept.
The whole concept of Twitter as a service is what makes it work. You are not just limited to the web page as an interface to the Twitter. There are so many free Twitter clients which are available. I use TweetDeck as a windows client. It gives a notification when there are updates to the tweets from the people I follow. It also integrates nicely with Facebook. That helps me to get a consolidated view.
Twitter and Facebook are so popular that there are clients available for mobile devices like cell phones. i have used Twitter client on a Nokia handset in one of the most remote places in India while travelling in a train.

Professional network

I use a service called Linkedin which helps people to update their professional history. I have found many ex-colleagues over linked in. But I think the concept hasn’t made it that big.

Social networks

I have been using Orkut for almost 4 years now. Overall its a good site to share photos and videos with the friends. It has other features like scraps which are personalized messages to friends and contacts. There are also communities in Orkut. I personally feel Orkut is more famous in India.
Recently I have started using Facebook and find it lot more competitive as compared to Orkut. Some of the features like instant notifications, personal wall, like / unlike and share with others are features which are much more intuitive. Both these sites are good for sharing information with friends and to have some fun online.

Social network related to Technology

It was almost a year back that I came across a site called StackOverflow. Even in my wildest dreams, I didn’t imagine that it will have such an impact on the developer community in such a short span of time. Its been a week or so since I became an active member of StackOverflow community. Previously I had been an active member of ASP.NET community. These community sites are kind of dedicated user groups and newsgroups which help developers to share information. People ask questions and receive answers and suggestions form others.
The place where StackOverflow differs is the way it treats the questions. It is driven by the community. Members can give votes to questions. For example if somebody asked a very good question you can give a thumbs up to that question and the person who asked the question gets some points. Similarly for the answers members can vote up or down based on how good or bad the answer is. I already experienced this when my first answer was voted down twice before someone accepted my other answer.
Another very good feature in Stackoverflow is the tagging of questions and topics. You can search questions based on tags like C# or ASP.NET etc. Based on the activity of the person they can have different badges like gold, bronze and silver.
There is also a wonderful concept in StackOverflow which is called reputation. With the number of points that you accumulate you get a reputation. Based on the reputation the access level keeps increasing to the features available in StackOverflow. For e.g. until you have about 20 points you cannot vote up or down a question or a answer. Until you have accumulated 100 reputation points you cannot post more that 2 questions within a span of 20 minutes.
There is also restriction on the number of links you can include in you answers up to certain number of reputation points. All this proves that it is all community driven.


With advances in mobile technologies and devices like iPhone and Windows phones more and more information will be available on the web which can be accessed from numerous devices. It will be a real challenge to keep up with technology. I am sure there will be next generation services and devices already in the pipeline.
For the time being its Twitter, Google Reader, StackOverflow and Delicious which are helping me keep up the heat. i am sure if I look back at this same post 12 months down the line there would have been lot more changes.
Social networking sites like Orkut and Facebook are good for keeping in touch with friends and relatives. As developers what we need is a much more focused interaction around the topics which might not interest every individual having some sort of identity on the Internet. And that is where StackOverflow works is my firm belief.
There might be many more things similar to what I have mentioned above. I would love to hear about them from the readers of this blog.
Until next time Happy Programming :)

Informative Workspaces


Way back in April 2008, when I had been to Tesco office in UK I had seen my team using Agile development practices. One of the thing which was quite noticeable was the big screen plasma TV in the corner of the team space displaying the latest build status of the project. Ever since I always wanted to have a similar setup for my team in Bangalore office as well.

Informative Workspace

I was reading The Art of Agile development by James Shore and one of the thing he suggests is to make use of informative workspaces. It basically means that we should share as much information as possible with all the team members in the best possible way. There are various ways of doing this.
I have personally used couple of them to share my ideas with the team. Initially we would use an excel sheet to track down the hours remaining for each task for each day. We were also using the XPlanner tool for tracking the tasks during an iteration. XPlanner has a very good burndown chart in its reports. It also used to show the effort for each team member. Another feature I liked about XPlanner was that it allowed us to track effort for any tasks using pairs. So if two people had paired on a task, we could record the effort for both the developers in the same record.
Due to reasons like better way of managing product and sprint backlog and also relatively good reports we moved from XPlanner to Team Foundation Server (TFS) 2008 and everything was integrated right into the Visual Studio IDE. I feel compared to many other commercial products Visual Studio still lacks in many of the features to support full fledged Agile development. But at a intermediate level it still gives us some good features in an integrated manner.
I have used the Burndown chart, Sprint View and also the Sprint Task Board reports from TFS over last 6 to 8 months. I export these reports into PDF files and share it with the team. The idea behind this exercise is that everyone in the team is aware of where we stand with the regards to the sprint objectives. But many a times people don’t know how to interpret these reports and get the best out of them.
Recently our team was moved to a different floor and we had a provision for fixing a big screen TV near to our workspaces as our team was seated very close to wall. We had been requesting for a plasma / LCD TV for quite some time. Finally our request was approved and we got a LDC TV for our team.
One of the first thing that we did was to make use of it to display the burn down chart for the current sprint. Along with the TV we also got a white board where we could add information which we would track daily during the sprint. These two things have made our daily stand ups very informative.
Along with the burn down chart we also display other things on the TV screen which includes
  • sprint view
  • build status for all the projects
  • coverage statistics for the projects
  • FxCop results
  • StyleCop results
  • NCover coverage summary for each project
Here is a photo of how we conduct our morning standup.
The white board is also used to show the following
  • planned story points for the sprint
  • burn down chart
  • status of tasks in progress and the developer or pair working on the task
  • product backlog items ready for test
  • defects fixed and ready for testing
  • Any impediments or issues that we need to address
This is very helpful for anybody from the management side to have a look at the board and tell whether we are on track or not. Also if somebody missed the standup, they can find out the latest status just by looking at the board. It also helps us in getting into a technical design discussion related to tasks in progress.
The above picture shows Mohamed Abdulla, myself, Samarjit Mishra and Amit Jain (from left to right) discussing some technical stuff :):)
Long time back when ThoughtWorks were working with our team in helping us adopt Agile, I remember Irfan Shah telling me how Anand Vishwanath made use of radiators for displaying the project status. I have also read about various teams using lava lamps to indicate the current build status. Its been only few weeks since we got the TV and white board for our team. The results so far have been very satisfying.
I do have plans of putting more information on these places. Some of the information that we display on the TV is as of the previous day. I would want to spend some time getting dynamic and up to date content so that all team members are aware of the latest proceedings.
Just to be on the funny side, I would also like to put a weird picture of the guy if someone breaks the build. It is not to offend anybody, but just to bring in some fun element and also enforce the practice of fixing the build as soon as its broken.
Lets see how these things progress. Until next time Happy Programming :):)