// Copyright (C) Microsoft Corporation. All Rights Reserved. using System; using System.Configuration; using System.ServiceModel; using System.Security.Permissions; namespace Microsoft.ServiceModel.Samples { // Define a service contract. [ServiceContract] public interface ICalculator { [OperationContract] double Add(double n1, double n2); } // Service class which implements the service contract. // Added code to write output to the console window public class CalculatorService : ICalculator { [PrincipalPermission(SecurityAction.Demand, Role = "Managers")] public double Add(double n1, double n2) { double result = n1 + n2; Console.WriteLine("Received Add({0},{1})", n1, n2); Console.WriteLine("Return: {0}", result); return result; } // Host the service within this EXE console application. public static void Main() { // Create a ServiceHost for the CalculatorService type. using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService))) { // Open the ServiceHost to create listeners and start // listening for messages. serviceHost.Open(); // The service can now be accessed. Console.WriteLine("The service is ready."); Console.WriteLine("Press to quit."); Console.WriteLine(); Console.ReadLine(); } } } }