We use dictionary to store the data in memory but the data in memory is increased then exception fire of Fault stage. how to handle this problem.
----------IServices------------
[ServiceContract]
public interface IMyService
{
[OperationContract()]
Dictionary<int, Car> getCarList();
}
----------Services------------
public class MyService : IMyService
{
private const String fileName = @"c:\\Car.txt";
public MyService()
{
if (myCar.dicCar == null)
{
myCar.dicCar = new Dictionary<int, Car>();
myCar.lastID = 0;
if (File.Exists(fileName))
{
StreamReader r = new StreamReader(fileName);
while (!r.EndOfStream)
{
String line = r.ReadLine();
String[] data = line.Split('^');
Car c = new Car();
if (data.Length == 5)
{
int id = Convert.ToInt32(data[0].Trim());
c.Manufacturer = data[1];
c.Name = data[2];
c.Model = data[3];
c.Price = Convert.ToDouble(data[4]);
myCar.dicCar.Add(id, c);
myCar.lastID = id > myCar.lastID ? id: myCar.lastID;
}
}
r.Close();
}
}
}
}
public Dictionary<int, Car> getCarList()
{
return myCar.dicCar;
}
in case of dictionary has recordrs about 1350 then exception fire : The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be used for communication because it is in the Faulted state