added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Scenario / Router / CS / service-calculator / CalculatorService.cs
blob46986ecc0de6c72d38123c3ad21d82ffb6fca6a9
1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2003-2005 Microsoft Corporation, All rights reserved.
3 // ----------------------------------------------------------------------------
4 namespace Microsoft.ServiceModel.Samples
6 using System;
7 using System.ServiceModel.Dispatcher;
8 using System.ServiceModel;
9 using System.Diagnostics;
10 using System.Configuration;
12 [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples/", SessionMode=SessionMode.Required)]
13 public interface ICalculatorService
15 [OperationContract(IsOneWay = false)]
16 int Add(int number);
18 [OperationContract(IsOneWay = false)]
19 int Subtract(int number);
22 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)]
23 public class CalculatorService : ICalculatorService
25 int total = 0;
27 int ICalculatorService.Add(int number)
29 this.total += number;
30 return this.total;
33 int ICalculatorService.Subtract(int number)
35 this.total -= number;
36 return this.total;
40 public class ServiceDriver
42 public static void Main(string[] args)
44 ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));
45 serviceHost.Open();
47 for (int i = 0; i < serviceHost.ChannelDispatchers.Count; i++)
49 ChannelDispatcher channelDispatcher = serviceHost.ChannelDispatchers[i] as ChannelDispatcher;
50 if (channelDispatcher != null)
52 for (int j = 0; j < channelDispatcher.Endpoints.Count; j++)
54 EndpointDispatcher endpointDispatcher = channelDispatcher.Endpoints[j];
55 Console.WriteLine("Listening on " + endpointDispatcher.EndpointAddress + "...");
60 Console.WriteLine();
61 Console.WriteLine("Press Enter to exit...");
62 Console.ReadLine();