I have an Adapter-based EntityCollection hosted in a WCF ServiceHostBase. (HelloWorld complexity)
The service is hosted as InstanceContextMode.Single
Strings and ints in the ServiceHostBase keep their values during its lfetime, but the EntityCollection is always empty, but not null, after the next call to the service.
Is there a restriction on the life of items in a the EntityCollection hosted in the WCF service layer?
[ServiceBehavior( InstanceContextMode = InstanceContextMode.Single)]
public class CustomerService : ICustomer
{
public EntityCollection<CustomerEntity> GetCustomers()
{
if (OperationContext.Current.Host.Extensions.Find<MyServiceState>()==null)
OperationContext.Current.Host.Extensions.Add(new MyServiceState());
return OperationContext.Current.Host.Extensions.Find<MyServiceState>().ToReturn;
}
}
class MyServiceState : IExtension<ServiceHostBase>
{
private string controlSample = "";
private EntityCollection<CustomerEntity> toReturn;
public void Attach(ServiceHostBase owner)
{
controlSample = "sdffffffffffffffffff";
toReturn = new EntityCollection<CustomerEntity>(new CustomerEntityFactory());
//FILL IT HERE
}
public void Detach(ServiceHostBase owner)
{
toReturn = null;
}
public EntityCollection<CustomerEntity> ToReturn
{
get { return toReturn; //controlSample here keeps its values }
set { toReturn = value; }
}
}