WCF Error: The underlying connection was closed: The connection was closed unexpectedly.

Hi Folks,

While i was developing a WCF service API for my enterprise application, I got an error while i’m calling a search function in the WCF. The WCF function is calling a stored procedure.

I tested the stored procedure and there is no issues with it at all, and the error was being thrown in my web when the data is being serialized and sent over the network.

The error message:

The underlying connection was closed: The connection was closed unexpectedly.

The point here is that i have other functions in the WCF work perfectly with no errors but only the search function is throwing an exception.

So, it is not configuration thing, it is something else i want to nail it down!

The only way to get the actual error message from calling a WCF service, is to install a tool called “Microsoft Service Trace Viewer” . Here is the download link:
http://www.microsoft.com/en-us/download/details.aspx?id=3138


After you install it, add the following section in the web.config before the closing of the configuration attribue:

<system.diagnostics>
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData= "traces.svclog" />
</listeners>
</source>
</sources>
</system.diagnostics>

Run your applicaiton, and execute the action that throws the exception then do the following:
1) Open the following path:
C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin

2) Double click on SvcTraceViewer.exe tool

3) From the File Menu, Click on Open.

4) Navigate to your project folder and you will find a file called: traces.svclog, select this file.

5) Check the actual WCF call that causes the error from the activity window and then see the details of the error in the right pane.



Hope this helps.
 

Leave a Reply

Your email address will not be published. Required fields are marked *


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>