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?
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.
Check the following:
- You have a lot of data so you need to extend the timeout in your .config file
- 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;
}
}
精彩评论