Previous | Home | Next |
There are three operations:
- Request-Reply Operations
- One-Way Operations
- Callback Operations
1)Request-Reply Operations: Request-Reply Operations implies the client issues a request in the form of a message, and blocks until it get the reply message. If the service does not respond within a default timeout of one minute, the client will get a TimeoutException. Request-reply is the default operation mode. Programming against request-reply operations is simple enough and resembles programming using the classic client/server model.
The returned response message containing the results or returned values is converted to normal method returned values. In addition, the proxy will throw an exception on the client side if there are any communication or service-side exceptions. With the exception of the NetPeerTcpBinding and NetMsmqBinding all bindings support request-reply operations.
2)One-Way Operations: In One-Way operation mode, client will send a request to the server and does not care whether it is success or failure of service execution. There are cases when an operation has no returned values, and the client does not care about the success or failure of the invocation.There is no need to wait, till server execute.
There is no return from the server side, it is one-way communication.Client will be blocked only for a moment till it dispatches its call to service. If any exception thrown by service will not reach the server.Client can continue to execute its statement, after making one-way call to server.
Configuring One-Way Operations:
The OperationContract attribute offers the Boolean IsOneWay property:
[AttributeUsage(AttributeTargets.Method)] public sealed class OperationContractAttribute : Attribute { public bool a {get;set;} //More members }
IsOneWay defaults to false, which means a request-reply operation (hence the WCF default). However, setting IsOneWay to TRue configures the method as a one-way operation:
[ServiceContract] interface IMyContract { [OperationContract(a = true)] void show( ); }
One-Way Operations and Sessionful Services
WCF design a sessionful contract with one-way operations:
[ServiceContract(SessionMode = SessionMode.Required)] interface IMyContract { [OperationContract(IsOneWay = true)] void show( ) }
Per-call services and one-way exceptions
In the case of a per-call service, when there is no transport session , if an exception takes place when invoking a one-way operation, the client is unaffected and can continue to issue calls on the same proxy instance:
[ServiceContract] interface IMyContract { [OperationContract(IsOneWay = true)] void operation1( ); [OperationContract] void operation2( ); } class MyService : IMyContract { public void operation1( ) { throw new Exception( ); } public void operation2( ) {} } //Client side when using basic binding: MyContractClient proxy = new MyContractClient( ); proxy.operation1( ); proxy.operation2( ); proxy.Close( );
3)Callback Operations: WCF supports allowing the service to call back to its clients.A service contract can have at most one callback contract. Callback operations are part of the service contract.It is up to the service contract to define its own callback contract.
Once defined, the clients are required to support the callback and provide the callback endpoint to the service in every call. To define a callback contract, the ServiceContract attribute offers the CallbackContract property of the type Type:
[AttributeUsage(AttributeTargets.Interface|AttributeTargets.Class)] public sealed class ServiceContractAttribute : Attribute { public Type CallbackContract {get;set;} //More members }
Example:
using System; using System.Collections.Generic; using System.Text; using System.ServiceModel; namespace CallbackApp { public interface IMathCalculationCallback { [OperationContract] void calculate(); } [ServiceContract(CallbackContract = typeof(IMathCalculationCallback)) public interface IMathCalculation { [OperationContract] void LongCalculations(int nParam1, int nParam2); } }
Previous | Home | Next |