开发者

Help me to chose instance management in WCF service

My scenerio is like this:

On the server there is an application which exposes a COM object allowing to interact with this application programaticaly. However I can connect only once through COM due to licence restrictions. So, after initialization a COM object will return me a more specified ConnectionObject.

I need an advice what management model I schould chose for my service which will be interacting with the Connecti开发者_高级运维onObject:

Per-Call Service:

I have two options here:

  1. I can log through COM, perform operation and Logout releasing the connection. But this logging process is somewhat time consuming.

  2. I could create some sort of singleton class which could keep reference to the ConnectionObject. The problem is that I do not know how to share the same instance of object through different instances of the service? Is it possible?

Singleton Service:

The problem of sharing ConnectionObject does not exists. Object will be created at the begining of life of the service and freed when service will be shut down. However I've read that using this kind of service is not recommended.

Thanks for any advices.


Given your requirements with the COM object, and the time consuming log in and out process - I would go with the singleton service. We use our WCF services like this all the time (also talking to legagy COM objects).

You can add the following attribute to the class definition of your WCF service to get the behaviour:

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)] 
public class MyService : IMyServiceContract
{
    [OperationBehavior]
    public void MyServiceCall ()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜