none
New to WCF...When to use Per-call, Per-session, singleton instances? Any real world examples please RRS feed

  • Question

  • Hello Good folks,

    I am trying to understand under what circumstances I can use each of them.

    I know there are lot of knowledgable folks here on this forum. can someone try to help me understand or point me to right direction?

    thanks much

    regards

    nath

    Tuesday, August 6, 2013 6:41 PM

Answers

  • Hi,

    Please try to refer to the following information:

    Per-Call:
    Per-call services are the Windows Communication Foundation default instantiation mode. When the service type is configured for per-call activation, a service instance, a common language runtime (CLR) object, exists only while a client call is in progress. Every client request gets a new dedicated service instance.
    The following image tells how this single-call activation works.

    1. The client calls the proxy and the proxy forwards the call to the service.
    2. Windows Communication Foundation creates a service instance and calls the method on it.
    3. After the method call returns, if the object implements IDisposable, then Windows Communication Foundation calls IDisposable.Dispose on it.
    Per-Session:

    Windows Communication Foundation can maintain a private session between a client and a particular service instance. When the client creates a new proxy to a service configured as session-aware, the client gets a new dedicated service instance that is independent of all other instances of the same service. That instance will remain in service usually until the client no longer needs it. Each private session uniquely binds a proxy to a particular service instance. Note that the client session has one service instance per proxy. If the client creates another proxy to the same or a different endpoint, that second proxy will be associated with a new instance and session.

    Singleton:
    The singleton service is the ultimate shareable service. When a service is configured as a singleton, all clients get connected to the same single well-known instance independently of each other, regardless of which endpoint of the service they connect to. The singleton service lives forever, and is only disposed of once the host shuts down. The singleton is created exactly once when the host is created.

    Using a singleton does not require clients to maintain a session with the singleton instance, or to use a binding that supports transport-level session. If the contract that the client consumes has a session, by closing the proxy the client will only terminate the session, not the singleton instance. In addition, the session will never expire. If the singleton service supports contracts without a session, those contracts will not be per-call—they too will be connected to the same instance.
    For more, please try to refer to the following:
    http://msdn.microsoft.com/en-us/magazine/cc163590.aspx#S1.

    The following articles give your many picture for you to understand, please try to refer to:
    http://www.dotnetfunda.com/articles/article912-3-ways-to-do-wcf-instance-management-per-call-per-session-and-single.aspx .

    A similar thread, please try to refer to:
    http://stackoverflow.com/questions/15104960/persession-vs-percall .

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 7, 2013 7:19 AM
    Moderator

All replies

  • Hi,

    Please try to refer to the following information:

    Per-Call:
    Per-call services are the Windows Communication Foundation default instantiation mode. When the service type is configured for per-call activation, a service instance, a common language runtime (CLR) object, exists only while a client call is in progress. Every client request gets a new dedicated service instance.
    The following image tells how this single-call activation works.

    1. The client calls the proxy and the proxy forwards the call to the service.
    2. Windows Communication Foundation creates a service instance and calls the method on it.
    3. After the method call returns, if the object implements IDisposable, then Windows Communication Foundation calls IDisposable.Dispose on it.
    Per-Session:

    Windows Communication Foundation can maintain a private session between a client and a particular service instance. When the client creates a new proxy to a service configured as session-aware, the client gets a new dedicated service instance that is independent of all other instances of the same service. That instance will remain in service usually until the client no longer needs it. Each private session uniquely binds a proxy to a particular service instance. Note that the client session has one service instance per proxy. If the client creates another proxy to the same or a different endpoint, that second proxy will be associated with a new instance and session.

    Singleton:
    The singleton service is the ultimate shareable service. When a service is configured as a singleton, all clients get connected to the same single well-known instance independently of each other, regardless of which endpoint of the service they connect to. The singleton service lives forever, and is only disposed of once the host shuts down. The singleton is created exactly once when the host is created.

    Using a singleton does not require clients to maintain a session with the singleton instance, or to use a binding that supports transport-level session. If the contract that the client consumes has a session, by closing the proxy the client will only terminate the session, not the singleton instance. In addition, the session will never expire. If the singleton service supports contracts without a session, those contracts will not be per-call—they too will be connected to the same instance.
    For more, please try to refer to the following:
    http://msdn.microsoft.com/en-us/magazine/cc163590.aspx#S1.

    The following articles give your many picture for you to understand, please try to refer to:
    http://www.dotnetfunda.com/articles/article912-3-ways-to-do-wcf-instance-management-per-call-per-session-and-single.aspx .

    A similar thread, please try to refer to:
    http://stackoverflow.com/questions/15104960/persession-vs-percall .

    Best Regards.


    Amy Peng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 7, 2013 7:19 AM
    Moderator
  • thank you so much Amy.

    regards

    Wednesday, August 7, 2013 3:39 PM