我有一个名为’Template’的抽象类,定义如下:
[DataContract] public abstract class Template { [DataMember] public virtual int? Id { get; set; } [DataMember] public virtual string Title { get; set; } [DataMember] public virtual byte[] TemplateDoc { get; set; } [DataMember] public virtual bool IsSystemTemplate { get; set; } }
两个派生类:UserTemplate和SystemTemplate实现上面的抽象类,定义如下:
public class UserTemplate : Template { [DataMember] public virtual Int32? OfficeId { get; set; } [DataMember] public virtual Int32? UserId { get; set; } protected UserTemplate() { } public UserTemplate(string title,byte[] templateDoc,string templateDocName,TemplateType templateType,int officeId,int? userId) { this.Title = title; this.TemplateDoc = templateDoc; this.IsSystemTemplate = false; this.OfficeId = officeId; this.UserId = userId; } } public class SystemTemplate : Template { [DataMember] public virtual Int32? MultiListGroupId { get; set; } protected SystemTemplate() { } public SystemTemplate(string title,int multiListGroupId) { this.Title = title; this.TemplateDoc = templateDoc; this.IsSystemTemplate = true; this.MultiListGroupId = multiListGroupId; } }
List<Template> GetTemplatesByTemplateType(int officeId,int? userId,TemplateType templateType)
我收到此错误:
System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
解决方法
是的,问题是您的抽象基类需要使用KnownType和XmlInclude属性进行修饰.见:
http://geekswithblogs.net/ugandadotnet/archive/2008/05/27/serializing-an-abstract-data-contract.aspx