views:

20

answers:

2

I'm receiving this error message when trying to return data from a WCF service.

"The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:00:59.9960000'"

It is misleading because it shows ~59 seconds, but the exception happens is about 2 seconds. The last time I received this error message it had to do with an infinite loop caused by serializing entity framework objects. Luckily, I had just made the change so it was easy to spot.

This time I don't know what changed to cause this. I diffed the entity framework classes to find out there haven't been any changes. As far as I know the database has also stayed the same, although I don't know how to prove that since it's fairly large.

If I step through the WCF code with a debugger, I see that it is correctly gathering data. It even tries to return the information. But, in the client side proxy I receive the exception on this line of code:

return Channel.GetDocuments( user, criterion );

Does anybody have any insight or tools that may help me track down this exception?

A: 

Check the following:

  1. You have a lot of data so you need to extend the timeout in your .config file
  2. Most likely in my experience is that you have a circular reference in the type you are returning from the the WCF function.

so if you have a class that has something like this, WCF will be unhappy

[DataContract]
public class MyClass
{
    public ChildObject(int i)
    {
    }

    [DataMember]
    public MyClass Parent
    {
        get;
        set;
    }
}
Steve Sheldon
I also suspect that it is a circular reference. Do you have a clever way of finding which `DataMember` is the culprit? I've looked through the properties and nothing 'obvious' is jumping out.
Jerod Houghtelling
I look for two things.... 1. A return type that is of the same type as the caller. 2. This is usually what it is... a property, which is a class that has properties and one of these is of the same type as a parent somewhere in the object graph. No trick I know of though off the top of my head.
Steve Sheldon
A: 

I found the problem. It had to do with a column being removed from the database and the entity framework models were not updated. It wasn't a circular loop that I had previously thought.

Here is the trick that pointed me in the right direction.

Client Side Proxy

public List<ImageData> GetDocuments( User user, DocumentSearchCriterion criterion )
{
    Channel.GetDocuments( user, criterion );
}

WCF Side Service

public List<ImageData> GetDocuments( User user, DocumentSearchCriterion criterion )
{
    List<ImageData> documents = new DocumentRepository().GetDocuments( user, criterion );

    // Temporary test to see if we can serialize the data. This is only for debugging
    // purposes and needs to be removed from production code.
    DataContractSerializer serializer = new DataContractSerializer( documents.GetType() );
    using( FileStream stream = new FileStream( "SerializerOutput.xml", FileMode.Create ) )
    {
        // This line will give an exception with useful details while debugging.
        serializer.WriteObject( stream, documents );
    }

    return documents;
}

Hope that helps anybody else with this generic and misleading exception.

Jerod Houghtelling