一个现有的连接被强行WCF中远程主机关闭 [英] An existing connection was forcibly closed by the remote host in WCF

查看:165
本文介绍了一个现有的连接被强行WCF中远程主机关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个抽象类,称为模板定义为:

I have an abstract class called 'Template' defined as:

[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实现上述抽象类,其定义为:

Two derived classes: UserTemplate and SystemTemplate implements above abstract class, which are defined as:

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, byte[] templateDoc, string templateDocName, TemplateType templateType, int multiListGroupId)
    {
        this.Title = title;
        this.TemplateDoc = templateDoc;
        this.IsSystemTemplate = true;
        this.MultiListGroupId = multiListGroupId;
    }
}

现在,当我尝试拨打以下服务方法:

Now, when I try to call following service method:

List<Template> GetTemplatesByTemplateType(int officeId, int? userId, TemplateType templateType)

我得到这个错误:

I get this error:

System.Net.Sockets.SocketException:一个现有的连接被强行关闭远程主机

System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

是因为我想返回一个抽象类的原因吗?
它如果我尝试使用单元测试来调用此方法运行正常。

Is it because of the reason that I am trying to return an abstract class?
It runs fine if I try to call this method using unit test.

推荐答案

是的,问题是它需要与KnownType装饰和XmlInclude属性的抽象基类。在这里看到:<一href="http://geekswithblogs.net/ugandadotnet/archive/2008/05/27/serializing-an-abstract-data-contract.aspx">http://geekswithblogs.net/ugandadotnet/archive/2008/05/27/serializing-an-abstract-data-contract.aspx

Yes, the problem is your abstract base class which needs to be decorated with the KnownType and XmlInclude attributes. See here: http://geekswithblogs.net/ugandadotnet/archive/2008/05/27/serializing-an-abstract-data-contract.aspx

这篇关于一个现有的连接被强行WCF中远程主机关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆