there is a data contract (say, `EmployeeView`) in my WCF service. I have decorated it with `Serializable` attribute, and all members are marked as `DataMember`
A method in the WCF is returning `List<EmployeeView>`.
When I execute this method through WCF Test client or MVC app, it gets executed successfully, but while transferring result it is giving an error of `The underlying connection was closed: The connection was closed unexpectedly`. Is `List<EmployeeView>` not
serialized though `EmployeeView` is marked as serialized?
WCF serializes Lists<T> as arrays, so that should work. Make sure your DataContracts are setup correctly, like this:
[DataContract]
public class EmployeeList
{
[DataMember]
public int Count { get; set; }
[DataMember]
public List<EmployeeView> ListOfEmployees
{
{ get; set; }
}
}
[DataContract]
public class EmployeeView
{
[DataMember]
public string EmployeeName { get; set; }
// more properties
}
nirman.doshi
Participant
1520 Points
775 Posts
Is List<T> is serializable by default when T is serializable?
Jan 22, 2013 05:56 AM|LINK
there is a data contract (say, `EmployeeView`) in my WCF service. I have decorated it with `Serializable` attribute, and all members are marked as `DataMember`
A method in the WCF is returning `List<EmployeeView>`.
When I execute this method through WCF Test client or MVC app, it gets executed successfully, but while transferring result it is giving an error of `The underlying connection was closed: The connection was closed unexpectedly`. Is `List<EmployeeView>` not serialized though `EmployeeView` is marked as serialized?
Software Developer
Vadodara, India
DarrellNorto...
All-Star
86555 Points
9624 Posts
Moderator
MVP
Re: Is List<T> is serializable by default when T is serializable?
Jan 22, 2013 09:36 AM|LINK
WCF serializes Lists<T> as arrays, so that should work. Make sure your DataContracts are setup correctly, like this:
[DataContract] public class EmployeeList { [DataMember] public int Count { get; set; } [DataMember] public List<EmployeeView> ListOfEmployees { { get; set; } } } [DataContract] public class EmployeeView { [DataMember] public string EmployeeName { get; set; } // more properties }You can run into problems if you are using inheritance. If that is an issue, use the KnownTypes attribute. See this article for details: http://msdn.microsoft.com/en-us/magazine/gg598929.aspx
Darrell Norton's Blog
Please click "Mark as Answer" if this helped you.
nirman.doshi
Participant
1520 Points
775 Posts
Re: Is List<T> is serializable by default when T is serializable?
Jan 22, 2013 05:27 PM|LINK
Hi Darrel,
Thanks for the link you provided, and I came across something which will be very much helpful for me.
however, I have tried adding "knowntype", but it didn't work.
Also, i tried removing inheritance in data contract and that too didn't work.
whatever attempt I do I get same error message saying, "The underlying connection was closed: The connection was closed unexpectedly."
I am clueless on this to be honest
Software Developer
Vadodara, India
Haixia Xie -...
Contributor
3022 Points
294 Posts
Microsoft
Re: Is List<T> is serializable by default when T is serializable?
Jan 23, 2013 08:53 AM|LINK
To troubleshoot the issue, please enable tracing for your service and inspect the logs to help to dignose the problem.
http://msdn.microsoft.com/en-us/library/ms733025.aspx
Best Regards.
Feedback to us
Develop and promote your apps in Windows Store