wcf OperationContextScope 处置

编程入门 行业动态 更新时间:2024-10-27 09:42:19
本文介绍了wcf OperationContextScope 处置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个 c# 应用程序,它使用 OperationContextScope scope = new OperationContextScope(i.InnerChannel); 调用 wcf 服务;

I have a c# app that calls a wcf serivce using OperationContextScope scope = new OperationContextScope(i.InnerChannel);

我需要让连接保持打开状态,因此我无法使用 Using 语句处理 OperationContextScope.但是,在查看内存分析器时,我看到了数百个 OperationContextScope.我需要处理范围,但是当我调用 .Dispose() 时,我收到一条错误消息,说它不正常.我不知道为什么我不能处置范围.

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.

有谁知道如何正确处理 OperationContextScope ?以下是我的部分代码.

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);

推荐答案

来自 http://msdn.microsoft/en-us/library/system.servicemodel.operationcontextscope.aspx:

创建 OperationContextScope 时,当前 OperationContext被存储并且新的 OperationContext 成为由目前的财产.当 OperationContextScope 被释放时,原始 OperationContext 恢复.

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();

这篇关于wcf OperationContextScope 处置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 19:43:50,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141309.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:wcf   OperationContextScope

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!