Have you ever gotten the following error working with WCF services?
System.ServiceModel.CommunicationException: The underlying connection was closed: The connection was closed unexpectedly.
In your frustration of pulling your hair because the lack of more information you went to Google, pasted the error message and found this blog. Here I will tell you what to do.
- Open up your web.config/app.config on the server side and add the following
<system.diagnostics> <!-- This logging is great when WCF does not work. --> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> <listeners> <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\traces.svclog" /> </listeners> </source> </sources> </system.diagnostics> - A file called traces.svclog will be stored on your harddrive. This will contain the the error message that you're looking for. All you now need is the right tool to open it up. It is called svctraceviewer.exe and usually resides in the folder C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin. If you don't have this folder or anything like it, you go download the Microsoft Windows SDK from here.
- Now you can open your log and look for the error that is thrown. There you will find a detailed stacktrace of what's wrong.

Good Luck!

7 Comments
Uğur YILMAZ said
Thanks a lot. i have been looking for hours for my error. i found where it come from with this :)
Subodh said
Thanks a lot!! That's useful.
para said
thank you you are my hero
Sheldon said
You are a life saver I would have never found my problem without this being added. I was looking in the wrong spot for this error for over 3 hours.
Brent said
Great explanation - easy to read, understand and implement. Thanks!
Konamiman said
I was stuck with this problem for days. Without this tool I would never have discovered the problem: my service call was returning a DataTable without the TableName property set, thus throwing and InvalidOperationException. AAAARGH!!!
meghanad chitre said
This is Super !!