i have a WCF Client and a WCF service. For testing when i continually call a WCF method synchronously the memory usage jumps up by about 1 mb each time. How can i stop this happening ?
MyService.JobsClient Client = new MyService.JobsClient();
Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ServicePath"]);
Client.WCFGetSystemState(System.Environment.MachineName);
You should make sure that you close your client after you use it. You can follow this pattern (taken from MSDN):
MyService.JobsClient Client = new MyService.JobsClient();
Client.Endpoint.Address = new System.ServiceModel.EndpointAddress(ConfigurationManager.AppSettings["ServicePath"]);
try
{
Client.WCFGetSystemState(System.Environment.MachineName);
Client.Close();
}
catch (TimeoutException timeout)
{
// Handle the timeout exception.
Client.Abort();
}
catch (CommunicationException commException)
{
// Handle the communication exception.
Client.Abort();
}