Multiple choice technology programming languages

You are developing a Calculator service which performs mathematical operation. How you can enable session in your WCF Calculator Service?

  1. [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples", SessionMode=SessionMode.Required)] public interface ICalculator{ [OperationContract] double AddTo(double n); }

  2. [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)] public class CalculatorService : ICalculator { double result = 0.0D; public double AddTo(double n) { return result+=n; } }

  3. a and b both

  4. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

Enabling sessions in WCF requires both: (1) marking the service contract with SessionMode.Required, and (2) setting InstanceContextMode to PerSession in the ServiceBehavior. Option A shows the contract requirement, Option B shows the service behavior - both are necessary.