问题
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);
回答1:
From http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontextscope.aspx:
When an OperationContextScope is created, the current OperationContext is stored and the new OperationContext becomes the one returned by the Current property. When the OperationContextScope is disposed, the original OperationContext is restored.
Clearly, they must be disposed in the reverse order they were created.
scope.Dispose();
来源:https://stackoverflow.com/questions/9492085/wcf-operationcontextscope-dispose