I have a c# app that calls a wcf serivce using OperationContextScope scope = new OperationContextScope(i.InnerChannel);
I need to leave the connections open so I cannot dispose the OperationContextScope with the Using statement. However when looking at the memory profiler I am seeing hundreds of OperationContextScope’s. I need to dispose the scope but when I call .Dispose() I get an error saying its out of order. I have no idea why I cannot dispose the scope.
Does anyone know how to correctly dispose OperationContextScope ? Below is part of my code.
BasicHttpBinding wsbinding = null;
OperationContextScope scope = null;
wsbinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
wsbinding.MaxBufferSize = 2147483647;
wsbinding.MaxReceivedMessageSize = 2147483647;
wsbinding.Name = "BasicHttpBinding_Iretail";
i = new IretailClient(wsbinding, new EndpointAddress(commonStuff.EndpointAddress));
scope = new OperationContextScope(i.InnerChannel);
From http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontextscope.aspx:
Clearly, they must be disposed in the reverse order they were created.