Section C.6. Operations and Calls


C.6. Operations and Calls

  1. Do not treat one-way calls as asynchronous calls.

  2. Do not treat one-way calls as concurrent calls.

  3. Expect exceptions out of a one-way operation.

  4. Enable reliability even on one-way calls. Use of ordered delivery is optional for one-way calls.

  5. Avoid one-way operations on a sessionful service. If used, make it the terminating operation:

     [ServiceContract(SessionMode = SessionMode.Required)] interface IOrderManager {    [OperationContract]    void SetCustomerId(int customerId);    [OperationContract(IsInitiating = false)]    void AddItem(int itemId);    [OperationContract(IsInitiating = false)]    decimal GetTotal( );    [OperationContract(IsOneWay = true,IsInitiating = false,IsTerminating = true)]    void ProcessOrders( ); } 

  6. Name the callback contract on the service side after the service contract suffixed by Callback:

     interface IMyContractCallback {...} [ServiceContract(CallbackContract = typeof(IMyContractCallback))] interface IMyContract {...} 

  7. Strive to mark callback operations as one-way.

  8. Use callback contracts for callbacks only.

  9. Avoid mixing regular callbacks and events on the same callback contract.

  10. Event operations should be well-designed:

    1. void return type

    2. No out parameters

    3. Marked as one-way operations

  11. Avoid using raw callback contracts for event management, and prefer using the publish-subscribe framework.

  12. Always provide explicit methods for callback setup and teardown:

     [ServiceContract(CallbackContract = typeof(IMyContractCallback))] interface IMyContract {    [OperationContract]    void DoSomething( );    [OperationContract]    void Connect( );    [OperationContract]    void Disconnect( ); } interface IMyContractCallback {...} 

  13. Use the type-safe DuplexClientBase<T,C> instead of DuplexClientBase<T>.

  14. Use the type-safe DuplexChannelFactory<T,C> instead of DuplexChannelFactory<T>.

  15. When debugging or in intranet deployment of callbacks over WSDualHttpBinding, use the CallbackBaseAddressBehaviorAttribute with CallbackPort set to 0:

     [CallbackBaseAddressBehavior(CallbackPort = 0)] class MyClient : IMyContractCallback {...} 




Programming WCF Services
Programming WCF Services
ISBN: 0596526997
EAN: 2147483647
Year: 2004
Pages: 148
Authors: Juval Lowy

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net