2

I tried return a IEnumerable in WCF service

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;
}

Client

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

I get this error :

An existing connection was forcibly closed by the remote host

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Mhmt
  • 759
  • 3
  • 22
  • 45
  • 1
    possible duplicate of [An existing connection was forcibly closed by the remote host in WCF](http://stackoverflow.com/questions/2087680/an-existing-connection-was-forcibly-closed-by-the-remote-host-in-wcf) – gbjbaanb Apr 20 '15 at 07:50
  • I could not solve by this link. – Mhmt Apr 20 '15 at 07:54
  • Turn on tracing for better information http://stackoverflow.com/questions/4271517/how-to-turn-on-wcf-tracing – wiero Apr 20 '15 at 07:56

1 Answers1

3

Try making your IEnumerable a strongly typed collection. Wcf behaves well when using a Collection<T> or List<T> in the signature of an operationcontract

Roland Pheasant
  • 1,161
  • 8
  • 8
  • This S/O article is an alternative to generics/typed enums https://stackoverflow.com/questions/3101756/using-wcf-with-abstract-classes – tgolisch Jun 21 '22 at 20:27