1 // ----------------------------------------------------------------------------
2 // Copyright (C) 2003-2005 Microsoft Corporation, All rights reserved.
3 // ----------------------------------------------------------------------------
4 namespace Microsoft
.ServiceModel
.Samples
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)]
18 [OperationContract(IsOneWay
= false)]
19 int Subtract(int number
);
22 [ServiceBehavior(InstanceContextMode
= InstanceContextMode
.PerSession
)]
23 public class CalculatorService
: ICalculatorService
27 int ICalculatorService
.Add(int number
)
33 int ICalculatorService
.Subtract(int number
)
40 public class ServiceDriver
42 public static void Main(string[] args
)
44 ServiceHost serviceHost
= new ServiceHost(typeof(CalculatorService
));
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
+ "...");
61 Console
.WriteLine("Press Enter to exit...");