Skip to Main Content
Programming WCF Services
book

Programming WCF Services

by Juval Lowy
February 2007
Intermediate to advanced content levelIntermediate to advanced
634 pages
16h 1m
English
O'Reilly Media, Inc.
Content preview from Programming WCF Services

Concurrency Management

  1. Always provide thread-safe access to:

    1. Service in-memory state with sessionful or singleton services

    2. Client in-memory state during callbacks

    3. Shared resources

    4. Static variables

  2. Prefer ConcurrencyMode.Single (the default). It enables transactional access and it is thread-safe without any effort.

  3. Keep operations on single-mode sessionful and singleton services short in order to avoid blocking other clients for long.

  4. When using ConcurrencyMode.Multiple, you must use transaction auto-completion.

  5. Consider using ConcurrencyMode.Multiple on per-call services to allow concurrent calls.

  6. Transactional singleton service with ConcurrencyMode.Multiple must have ReleaseServiceInstanceOnTransactionComplete set to false:

    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single,
                     ConcurrencyMode = ConcurrencyMode.Multiple,
                     ReleaseServiceInstanceOnTransactionComplete = false)]
    class MySingleton : IMyContract
    {...}
  7. Never self-host on a UI thread and call the service by the UI application.

  8. Never allow callbacks to the UI application that called the service unless the callback posts the call using SynchronizationContext.Post( ).

  9. Use the asynchronous calls pattern on the client side only.

  10. When supplying the proxy with both synchronous and asynchronous methods, apply the FaultContractAttribute only to synchronous methods.

  11. Do not mix transactions with asynchronous calls.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Programming WCF Services, 3rd Edition

Programming WCF Services, 3rd Edition

Juval Lowy
Mastering ASP.NET Web API

Mastering ASP.NET Web API

Mithun Pattankar, Malendra Hurbuns

Publisher Resources

ISBN: 0596526997Supplemental ContentErrata Page