Skip to main content

WCF: The connection was closed unexpectedly

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.

  1. Open up your web.config/app.config on the server side and add the following

    <!-- This logging is great when WCF does not work. -->
    <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
    <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "c:\traces.svclog" />

  2. 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

  3. 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.
    stack trace

Good Luck!

comments powered by Disqus