0

I'm Getting the infamous "the underlying connection was unexpectedly closed" error in wcf when calling a particular method. If I comment out this method call in the client, other calls work fine.

According to other posts regarding this error; the main two reasons are either that too much data was requested or the returned data type wasn't of data contract compatible.

However neither of the two reasons suits my situation. I'm only requesting a very small amount of data (a handful of strings in a dictionary). Also the method returns a HybridDictionary which is already serializable (no custom type is being returned).

One thing worth mentioning is the returned HybridDictionary's values are of type ArrayList which should always contain string though. Could the ArrayList be the problem? If so any suggestion to get around this?

By the way, without WCF I can call this method without any problem in a console project.

Seymour
  • 7,043
  • 12
  • 44
  • 51
dragonfly02
  • 3,403
  • 32
  • 55

1 Answers1

0

"The underlying connection was unexpectedly closed" error can occur for several reasons. The best way to determine the root cause may be to enable WCF Tracing on both the client application and host service. Oftentimes, the WCF Trace log will reveal issues that were previously “hidden”.

http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx

Seymour
  • 7,043
  • 12
  • 44
  • 51
  • thanks for the link but unfortunately wcf trace didn't help as (like other posts have saide) trace doesn't point to the real cause of the error. Eventually I found from one of the comments in this post http://stackoverflow.com/questions/232078/common-wcf-exception-connection-unexpectedly-closed that the one reason of this error is wcf doesn't like lazy loading data structure so if anyone using Linq in wcf it needs to call ToList or ToArray so that wcf knows how to do the serialisation. – dragonfly02 Nov 20 '14 at 13:46