wcf OperationContextScope dispose

扶醉桌前 提交于 2019-12-23 06:10:33

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!