As the questions states. I am unable to send List<T> over WCF. I cannot understand why and I have been searching high and low over the internet for the past week without any concrete answers. I keep getting a SocketException: An existing connection was forcibly closed by the remote host. However, if I call a method that only returns a string, it works without problems.
I am hosting my WCF on IIS Express 7.5. I can confirm that I can access my service via my browser or other devices on my local network via my machine’s IP.
If it’s of any help, I am actually following this tutorial:
http://www.c-sharpcorner.com/uploadfile/urmimalapal/creating-a-windows-phone-7-application-consuming-data-using-a-wcf-service/
When I attempt to call FindEmployee, I get that error. I have also created another method that simply returns a string and calling it works fine. No errors. I have tried it on my WP7 emulator, WCF Test Client and WCFStorm and they all exhibit the same problem with List<T> trying to be returned and string being returned with no problems. I have also confirmed the list is being populated properly when my Linq statement hits the breakpoint. It’s definitely WCF refusing to send my List<T>.
Edit:
This is the XML reply I’m getting from WCFStorm when I attempt to call a method that throws a List<T>.
<FindVendor> <MethodParameters> <SocketException> <ErrorCode>10054</ErrorCode> <Message>An existing connection was forcibly closed by the remote host</Message> <SocketErrorCode>ConnectionReset</SocketErrorCode> <NativeErrorCode>10054</NativeErrorCode> <Data> <KeysAndValues attr0="KeyValuePairArray" isNull="false" /> </Data> <InnerException isNull="true" /> <TargetSite>Int32 Read(Byte[], Int32, Int32)</TargetSite> <StackTrace>at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)</StackTrace> <HelpLink isNull="true" /> <Source>System</Source> </SocketException> </MethodParameters> </FindVendor>
I haven’t bothered to download any sample code associated with the tutorial, but I notice the
MyEmployeeentity is not defined in the tutorial. You should ensure that it is marked with the[Serializable]attribute like so:There is also the possiblity that you will have to declare KnownTypes to the serialiser, depending on what you are doing – you should post the piece of code, and maybe turn on WCF logging to get you a better error message.