【问题标题】:How to return IEnumerable in WCF ? An existing connection was forcibly closed by the remote host如何在 WCF 中返回 IEnumerable?现有连接被远程主机强行关闭
【发布时间】:2015-04-20 07:49:02
【问题描述】:

我尝试在 WCF 服务中返回一个 IEnumerable

IService1.cs

[OperationContract] 
IEnumerable GetAllTasks(string PersonName);

Service1.cs

MyEntities db=new MyEntities ();
private IEnumerable getAllTask;

public IEnumerable GetAllTasks(string PersonName)
{
      getAllTask= db.GetAllTaskOfPerson(PersonName).ToList();
      return getAllTask;
}

客户

Service.ServiceClient ws=new Service.ServiceClient().ToList();
grid.DataSource=ws.GetAllTasks("John");
grid.DataBind();

我得到这个错误:

一个现有的连接被远程主机强行关闭

【问题讨论】:

标签: c# wcf


【解决方案1】:

尝试使您的 IEnumerable 成为强类型集合。在操作合同的签名中使用Collection<T>List<T> 时,Wcf 表现良好

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-13
    • 2021-05-12
    相关资源
    最近更新 更多