WCF instance context and concurrency

Source: Internet
Author: User

The instance Context pattern (InstanceContextMode) can be simply understood as the association between the service instance of the server and the service agent of the client. WCF has monotonic (Per-call), session (Per-session), and Singleton (single)


Monotonous (Per-call)

[ServiceBehavior (InstanceContextMode = instancecontextmode.percall)]    public class Testservice:itest


Session (Per-session)

[ServiceBehavior (InstanceContextMode = instancecontextmode.persession)]    public class Testservice:itest



Singleton (single)

[ServiceBehavior (InstanceContextMode = instancecontextmode.single)]    public class Testservice:itest


Second, concurrency

Defining concurrency Patterns with the ServiceBehaviorAttribute attribute

WCF defines three typical concurrency patterns for single, reentrant, and multiple for three typical concurrent processing policies.

Single: An instance context can only be used at a time to handle a singleton request, or multiple concurrent requests for only one instance context will be processed in a serial manner.

    [ServiceBehavior (InstanceContextMode = instancecontextmode.single,     ConcurrencyMode = ConcurrencyMode.Single)] Public    class Testservice:itest



Reentrant: An instance context object can only be used for processing a single request at some point. If the service operation involves a callback (Callback) to the client during execution, the instance context can be used for processing other service invocation requests during the callback process. If the service instance context is not processed for another request after the callback operation executes, the callback operation can be processed.

    [ServiceBehavior (InstanceContextMode = instancecontextmode.single,     ConcurrencyMode = ConcurrencyMode.Reentrant )] Public    class Testservice:itest



Multiple: An instance context can be used to process multiple service requests at the same time.

    [ServiceBehavior (InstanceContextMode = instancecontextmode.single,     concurrencymode = ConcurrencyMode.Multiple) ] Public    class Testservice:itest



WCF instance context and concurrency

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.