It describes the protocol of message exchanges a consumer must engage in to converse properly with the service. WCF supports three MEP's . They are
- Request/Response
- OneWay
- Duplex
Request/Response:-
This is the most common MEP' and very little has to be done to set it up because the default value for the IsOneWay property of OperationContractAttribute is false. Thus as long as you don't have IsOneWay = True and you are not in a Duplex channel setting, you are using Request/Response.If you are using Request/Response message, then a response message , is still going back to the consumer when the operation called. Also this is two way communication channel enables the service to issue faults, returns transaction contexts, or both.
Example:-
[ServiceContract]
public interface ILogisticsService
{
[OperationContract()]
WorkOrderAcknowledgement SubmitWorkorder(WorkOrder workorder);
[OperationContract]
void CancelWorkOrder(int workOrderNumber);
}
IsOneWay:-
In describes, you simple wants to send message off to a service and have it trigger some sort of business logic, and you are not in fact interested in receiving anything back from the service . in such cases, you might want to use OneWay MEP, that is have the consumer simple send one-way message into the service endpoint with out any response beck from the service.
Example :-
[Servicecontract]
public Interface ILogicService
{
[OperationContract(IsOneWay = true)]
void CancelWorkOrder(int workOrderNumber);
}
There are some point keep in mind when you are using OneWay MEP.
- It can not be used in Conjuction with the FaultContractAttributes because for a service to issue faults.
- It can be dangerous just to send off a One-Way message and not have some assurances that is arrived and was processed.
- If you want to queued message delivery, the OneWay MEP is your only Choice.
- Also be aware that is doe not conform to the asynchronous, send - and-forget semantics that one might think it does, given the name = "OneWay"
Duplex:-
This is a two-way message channel whose usage might be applicable in either of these two situations.
- The consumer sends a message to the service to initiate some longer-running processing and then subsequently requires notification back from the service. configuring that the requested processing has been done.
- The consumer needs to be able to receive unsolicited messages from the service.
Example :-
[ServiceContract]
Interface IGreetingHandler
{
[OperationContract(IsOneWay = true)]
Void GreetingProduced(string greeting);
}
[ServiceContract (callbackContract = typeof(IGreetingHandler))]
Interface IGreetingService
{
[OperationContract(IsOneWay = true)]
Void RequestGreeting(string name);
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode .persession)]
Class GreetingService :IGreetingService
{
public Void RequestGreeting(string name)
{
Console.WriteLine("In Service.Greet");
IGreetingHandler CallbackHandler = OperationContext.Current.GetCallbackChannel<IGreetingHandler>();
Callbackhandler.GreetingProduced("hello" + name);
}
}
No comments :
Post a Comment