Do not treat one-way calls as asynchronous calls.
Do not treat one-way calls as concurrent calls.
Expect exceptions out of a one-way operation.
Enable reliability even on one-way calls. Use of ordered delivery is optional for one-way calls.
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( ); }
Name the callback contract on the service side after the service contract suffixed by Callback:
interface IMyContractCallback {...} [ServiceContract(CallbackContract = typeof(IMyContractCallback))] interface IMyContract {...}
Strive to mark callback operations as one-way.
Use callback contracts for callbacks only.
Avoid mixing regular callbacks and events on the same callback contract.
Event operations should be well-designed:
void return type
No out parameters
Marked as one-way operations
Avoid using raw callback contracts for event management, and prefer using the publish-subscribe framework.
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 {...}
Use the type-safe DuplexClientBase<T,C> instead of DuplexClientBase<T>.
Use the type-safe DuplexChannelFactory<T,C> instead of DuplexChannelFactory<T>.
When debugging or in intranet deployment of callbacks over WSDualHttpBinding, use the CallbackBaseAddressBehaviorAttribute with CallbackPort set to 0:
[CallbackBaseAddressBehavior(CallbackPort = 0)] class MyClient : IMyContractCallback {...}