PrepAway - Latest Free Exam Questions & Answers

What should you do?

A service implements the following contract. (Line numbers are included for reference only)

01 [ServiceContract(SessionMode = SessionMode.Required)]
02 public interface IContosoService
03 {
04 [OperationContract(IsOneWay = true, IsInitiating = true)]
05 void OperationOne(string value);
06
07 [OperationContract(IsOneWay = true, IsInitiating = false)]
08 void OperationTwo(string value);
09 }

The service is implemented as follows:
10 class ContosoService: IContosoService
11 {
12 public void OperationOne(string value) {…}
13 …
14 public void OperationTwo(string value) {…}
15 }

ContosoService uses NetMsmqBinding to listen for messages. The queue was set up to use transactions for adding and removing messages.
You need to ensure that OperationOne and OperationTwo execute under the same transaction context when they are invoked in the same session.
What should you do?

PrepAway - Latest Free Exam Questions & Answers

A.
Insert the following attribute to OperationOne on lContosoService
[TransactionFlow(TransactionFlowOption.Mandatory)]
Insert the following attribute to OperationTwo on IContosoService
[TransactionFlow(TransactionFlowOption.Mandatory)]

B.
Insert the following attribute to OperationOne on ContosoService
[OperationBehavior(TransactonScopeRequired=true, TransactionAutoComplete=false)]
Insert the following attribute to OperationTwo on ContosoService.
[OperationBehavior(TransactionScopeRequired=true, TransactionAutoComplete=true)]

C.
Add the following XML segment to the application config file in the system serviceModel/bindings configuration section
<netMsmqBinding>
<binding name=”contosoTx” durable=”true” receiveContextEnabled=”true” />
</netMsmqBinding>
Then use the NetMsmqBinding named contosoTx to listen for messages from the clients.

D.
Add the following XML segment to the application config file in the systemserviceModel/bindings configuration section.
<customBinding>
<binding name=”contosoTx”>
<transactionFlow />
<binaryMessageEncoding />
<msmqTransport durable=”true” />
</binding>
</customBinding>
Then use the CustommiBinding named contosoTx to listen fcw messages from the clients.

Explanation:
The OperationBehaviorAttribute attribute is a programming model feature that enables common features that developers otherwise must implement themselves.

The AutoDisposeParameters property controls whether parameter objects passed to an operation are disposed when the operation completes.
The TransactionAutoComplete property specifies whether the transaction in which the method executes is automatically committed if no unhandled exceptions occur.
The TransactionScopeRequired property specifies whether a method must execute within a transaction.
The Impersonation property specifies whether the service operation can, must, or cannot impersonate the caller’s identity.
The ReleaseInstanceMode property specifies when service objects are recycled during the method invocation process.

TransactionFlowOption is a ServiceBehavior feature

ServiceModel Transaction Attributes
(http://msdn.microsoft.com/en-us/library/ms730250(v=vs.90).aspx)

One Comment on “What should you do?


Leave a Reply