This is definitely incorrect implementation of Service class. It should return ResponseMessage instead of Stream.
And ResponseMEssage also should not have Finalizer method implemented - this is the root cause of such an error. Finalizer is executed in unpredictable time and closes web response and underlying stream in it. The right way is that ResponseMessage should implement IDisposable interface with Dispose method like
public void Dispose()
{
if (response != null)
{
response.Close();
response = null;
}
if (content != null)
{
content.Dispose();
content = null;
}
}
and Service methods e.g. Export should return ResponseMessage instead of Stream. Then the call to the method is going to be like this
using (var response = service.Export(search, searchArgs))
{
MultiResultsReaderXml resultsReaderXml = new MultiResultsReaderXml(response.Content);
foreach (var result in resultsReaderXml)
{
foreach (var evnt in result)
{
}
}
}
Thanks,
Sergei
... View more