是否有必要()使用自定义ServiceHostFactory时处置? [英] Is it necessary to Dispose() when using a custom ServiceHostFactory?

查看:145
本文介绍了是否有必要()使用自定义ServiceHostFactory时处置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

时,有必要使用自定义ServiceHostFactory时的Dispose()?

Is it necessary to Dispose() when using a custom ServiceHostFactory?

在我的WCF .svc文件我已经定义了一个自定义的工厂为: <%@ ServiceHost的工厂=Service.ServiceHostFactory%>

In my WCF .svc file I have defined a custom Factory as: <%@ ServiceHost Factory="Service.ServiceHostFactory" %>

似乎一处置()不被由于覆盖CreateServiceHost()方法没有被调用的应用程序调用服务的每次执行调用。 (此外,除其他事项外,不被每次通话后进行记录和我所生成的trace.xml文件说,它是由另一个进程使用)。

It appears that a Dispose() is not being called since the overridden CreateServiceHost() method is not being called at each execution of the application calling the service. (Also, among other things, logging is not being performed after each call and the trace.xml file I generated says that it is in use by another process).

我有装饰的服务 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] 所以我希望别的东西是怎么回事,我不知道。在将实例服务创建我处置的客户端应用程序()ING通过参考finally块,但它需要在服务器端执行,在工厂的类似操作?

I do have the service decorated with [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] so I expect something else is going on that I'm not aware of. In the client application where the instance to the service is created I am Dispose()'ing of the reference via a finally block but is it necessary to perform a similar operation in the Factory on the server side?

    Finally
        service.Dispose()
    End Try

感谢

推荐答案

服务主机工厂返回服务的主机的,而不是服务类的一个实例。工厂通常被称为一次每个激活服务,并将其返回主机使用,直到IIS应用程序池被回收。服务实例是由 IInstanceProvider ,而不是服务主机处理(尽管正在创建的主机,你可以,如果你想处置服务实例更改实例提供者 - 有关实例提供程序的详细信息,请参阅<一href="http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/31/wcf-extensibility-iinstanceprovider.aspx" rel="nofollow">http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/31/wcf-extensibility-iinstanceprovider.aspx和的http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iinstanceprovider.aspx).

The service host factory returns a service host, not an instance of the service class. The factory is usually called only once per activation of the service, and the host it returns is used until the IIS application pool is recycled. The service instance is handled by an IInstanceProvider, not the service host (although as you're creating the host you can change the instance provider if you want to dispose the service instance - for more information about instance providers, see http://blogs.msdn.com/b/carlosfigueira/archive/2011/05/31/wcf-extensibility-iinstanceprovider.aspx and http://msdn.microsoft.com/en-us/library/system.servicemodel.dispatcher.iinstanceprovider.aspx).

因此​​,在短期,你应该的没有的处置服务(或者是它的主人?),你是从服务主机工厂返回。如果你想处理服务的处置,你应该实现自己的实例提供商。

So in short, you should not dispose the service (or is it the host?) which you're returning from the service host factory. If you want to handle service disposal, you should implement your own instance provider.

这篇关于是否有必要()使用自定义ServiceHostFactory时处置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆