PrepAway - Latest Free Exam Questions & Answers

Which two actions should you perform?

A Windows Communication Foundation (WCF) solution uses the following contract:

[ServiceContract(SessionMode=SessionMode.Allowed)]
public interface IMyService
{
[OperationContract(IsTerminating=false)]
void Initialize();
[OperationContract(IsInitiating=false)]
void DoSomething();
[OperationContract(IsTerminating=true)]
void Terminate();
}

You need to change this interface so that:
* lnitialize is allowed to be called at any time before Terminate is called.
* DoSomething is allowed to be called only after Initialize is called, and not allowed to be called after Terminate is called.
* Terminate will be allowed to be called only after Initalize is called.

Which two actions should you perform? (Each correct answer presents part of the sdution. Choose two)

PrepAway - Latest Free Exam Questions & Answers

A.
Change the ServiceContract attribute of the IMyService interface to the following.
[ServiceContract(SessionMode=SessionMode.Required)]

B.
Change the ServiceContract attrbute of the IMyService interface to the following
[ServiceContract(SessionMode=SessionMode.Allowed)]

C.
Change the OperationContract attribute of the Initialize operation to the following.
[OperationContract(IsInitiating = true, IsTerminating = false)]

D.
Change the OperationContract attribute of the Terminate operation to the following
[OperationContract(IsInitiating = false, IsTerminating = true)]

Explanation:
OperationContractAttribute.IsInitiating
Gets or sets a value that indicates whether the method implements an operation that can initiate a session on the server (if such a session exists).

OperationContractAttribute.IsInitiating Property
(http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.isinitiating.aspx)

Example:

The following example is a service that implements a service contract that specifies three methods.
The service requires a session. If a caller’s first call is to any operation other than MethodOne,
the channel is refused and an exception is thrown. When a caller initiates a session by calling MethodOne,
that caller can terminate the communication session at any time by calling MethodThree.
MethodTwo can be called any number of times during a session.

C#
[ServiceContract(SessionMode=SessionMode.Required)]
public class InitializeAndTerminateService
{
[OperationContract(IsOneWay=true, IsInitiating=true, IsTerminating=false)]
public void MethodOne()
{
return;
}

[OperationContract(IsInitiating=false, IsTerminating=false)]
public int MethodTwo(int x, out int y)
{
y = 34;
return 0;
}

[OperationContract(IsOneWay=true, IsInitiating=false, IsTerminating=true)]
public void MethodThree()
{
return;
}
}

3 Comments on “Which two actions should you perform?


Leave a Reply