What should you do?

A Windows Communication Foundation (WCF) service has the following contract:

[ServiceContract]
public class ContosoService
{
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
[OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=false)]
void TxOp1(string value) {… };

[OperationContract(IsTerminating=true)]
[TransactionFlow(TransactionFlowOption.Mandatory)]
[OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=false)]
void TxOp2(string value)
{

OperationContext.Current.SetTransactionComplete();
}
}

The service and the clients that call the service use NetTcpBinding with transaction flow enabled.
You need to configure the service so that when TxOp1 and TxOp2 are invoked under the same client session,
they run under the same transaction context. What should you do?

A Windows Communication Foundation (WCF) service has the following contract:

[ServiceContract]
public class ContosoService
{
[OperationContract]
[TransactionFlow(TransactionFlowOption.Mandatory)]
[OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=false)]
void TxOp1(string value) {… };

[OperationContract(IsTerminating=true)]
[TransactionFlow(TransactionFlowOption.Mandatory)]
[OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=false)]
void TxOp2(string value)
{

OperationContext.Current.SetTransactionComplete();
}
}

The service and the clients that call the service use NetTcpBinding with transaction flow enabled.
You need to configure the service so that when TxOp1 and TxOp2 are invoked under the same client session,
they run under the same transaction context. What should you do?

A.
Update the service contract to read as follows.
[ServiceContract(SessionMode=SessionMode.Required)]
Add the following behavior to the service implementation
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerSession)]

B.
Update the service contract to read as follows.
[ServiceContract(SessionMode=SessionMode.Allowed)]
Add the following behavior to the service implementation.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single, ReleaseServiceInstanceOnTransactionComplete=false)]

C.
Update the service contract to read as follows
[ServiceContract(SessionMode=SessionMode.Allowed)]
Add the followng behavior to the service implementation.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.Single)]

D.
Update the service contract to read as follows.
[ServiceContract(SessionMode=SessionMode.Required)]
Add the following behavior to the service implementation.
[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)]

Explanation:
To participate in the same transaction both calls should be part of the same session.
SessionMode.Required is required to enforce sessions for the endpoint.

InstanceContextMode Enumeration
(http://msdn.microsoft.com/en-us/library/system.servicemodel.instancecontextmode.aspx)

SessionMode Enumeration
(http://msdn.microsoft.com/en-us/library/system.servicemodel.sessionmode.aspx)



Leave a Reply 1

Your email address will not be published. Required fields are marked *