Do I need Dispose () to use the custom ServiceHostFactory?

Do I need Dispose () to use the custom ServiceHostFactory?

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

Dispose () does not seem to be called because the overridden CreateServiceHost () method is not called every time the application invokes the service. (Also, among other things, logging is not performed after each call, and the trace.xml file that I created says that it is being used by another process).

I have a service decorated with [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] so I expect something else to happen that I don’t know about. In the client application where the service instance is created, I place the Dispose () link of the link through the finally block, but do I need to perform a similar operation in Factory on the server side?

  Finally service.Dispose() End Try 

thanks

+1
source share
1 answer

The factory service host returns a service node, not an instance of a service class. factory is usually called only once per service activation, and the host it returns is used until the IIS application pool is reused. The service instance is handled by IInstanceProvider and not the service host (although you can change the instance provider when creating the node if you want to delete the service instance - for more information on 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 ).

In short, you should not dispose of the service (or is it the host?) That you are returning from the factory service host. If you want to handle the removal of services, you must implement your own instance provider.

+4
source

Source: https://habr.com/ru/post/945077/


All Articles