WCF关闭连接/解除资源 [英] WCF Closing a connection/Releasing resources
问题描述
我最近将我的ASMX服务,WCF拿会话优势。
I've recently converted my ASMX service to WCF to take advantage of Sessions.
我查看了一些MSDN上的会话教程,但仍然不知道我有我的code一个很好的设置。截至目前它的工作原理,但我真的不知道为什么。
I've reviewed some of the Sessions tutorials on MSDN but still not sure I have a good setup in my code. as of now it works, but I'm not really sure why.
我
[ServiceContract
(SessionMode = SessionMode.Required,
Namespace = "http://smartshopservice.org")]
然后,我有
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
public class SmartShopService : SmartShopInterface
{
private static Shopper sh = new Shopper();
private List<aaa> data = new List<aaa>();
我的问题的第一部分是购物者是否是我的全局变量。我希望它一直在那里,而其他的都是诸如数据每个会话实例化。我还设置appropiately WebConfig。还有什么我需要做什么?
The first part of my question is whether Shopper is my "global" variables. I want it to always be there, while everything else such as "data" is instanciated per session. I've also setup WebConfig appropiately. Is there anything else I need to do?
我的第二个问题是如何关闭会话,并随后把所有这些变量?我的客户,现在是Web客户端,它是这样的沟通:
My second question is how to close a session, and then flush all these variables? My Client right now is a WebClient, it is communicating like this:
static GarfieldService.SmartShopInterfaceClient service
= new GarfieldService.SmartShopInterfaceClient();
这似乎工作,我有onbody = ASP.NET页的地叫,看起来像这样的功能:
It seems to work, and I have onbody="" of the ASP.NET page to call a function that looks like this:
[WebMethod]
public static bool Connect() {
try {
if (service.State
== System.ServiceModel.CommunicationState.Closed) {
service.Open();
return true;
}
else if (service.State
== System.ServiceModel.CommunicationState.Created) {
service.Open();
return true;
}
}
catch {}
return false;
}
所以我可以连接,但我怎么断开连接或关闭会话?
So I can connect, but how do I disconnect or close a session?
推荐答案
回复:全局,是使用静态的服务将作为一个全球性的,因为你使用的是PerSession的AAAvarible将以每股sesssion
Re: Globals, yes using a static on the service will act as a global, and because you are using a PerSession the "aaa" varible will be per sesssion.
回复:终止,尝试创建一个终止的操作和设置属性参数<一个href=\"http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isterminating.aspx\"相对=nofollow> IsTerminating =真。
Re: terminating, try creating a "terminate" operation and setting attribute parameter IsTerminating = true.
P.S。我不认为WebGet属性是相关的wsDualHttpBinding。
P.S. I dont think the WebGet attribute is relevant to the wsDualHttpBinding.
这篇关于WCF关闭连接/解除资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!