added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Basic / Contract / Service / Oneway / CS / service / service.cs
blobde43e03c323b92da09cffd71eccf811f0593e748
2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
4 using System;
5 using System.Configuration;
6 using System.ServiceModel;
8 namespace Microsoft.ServiceModel.Samples
10 // Define a service contract.
11 [ServiceContract(Namespace = "http://Microsoft.ServiceModel.Samples")]
12 public interface IOneWayCalculator
14 [OperationContract(IsOneWay = true)]
15 void Add(double n1, double n2);
16 [OperationContract(IsOneWay = true)]
17 void Subtract(double n1, double n2);
18 [OperationContract(IsOneWay = true)]
19 void Multiply(double n1, double n2);
20 [OperationContract(IsOneWay = true)]
21 void Divide(double n1, double n2);
24 // Service class which implements the service contract.
25 // Added code to write output to the console window
26 [ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall)]
27 public class CalculatorService : IOneWayCalculator
29 public void Add(double n1, double n2)
31 Console.WriteLine("Received Add({0},{1}) - sleeping", n1, n2);
32 System.Threading.Thread.Sleep(1000 * 5);
33 double result = n1 + n2;
34 Console.WriteLine("Processing Add({0},{1}) - result: {2}", n1, n2, result);
37 public void Subtract(double n1, double n2)
39 Console.WriteLine("Received Subtract({0},{1}) - sleeping", n1, n2);
40 System.Threading.Thread.Sleep(1000 * 5);
41 double result = n1 - n2;
42 Console.WriteLine("Processing Subtract({0},{1}) - result: {2}", n1, n2, result);
45 public void Multiply(double n1, double n2)
47 Console.WriteLine("Received Multiply({0},{1}) - sleeping", n1, n2);
48 System.Threading.Thread.Sleep(1000 * 5);
49 double result = n1 * n2;
50 Console.WriteLine("Processing Multiply({0},{1}) - result: {2}", n1, n2, result);
53 public void Divide(double n1, double n2)
55 Console.WriteLine("Received Divide({0},{1}) - sleeping", n1, n2);
56 System.Threading.Thread.Sleep(1000 * 5);
57 double result = n1 / n2;
58 Console.WriteLine("Processing Divide({0},{1}) - result: {2}", n1, n2, result);
62 // Host the service within this EXE console application.
63 public static void Main()
65 // Create a ServiceHost for the CalculatorService type and provide the base address.
66 using (ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService)))
68 // Open the ServiceHostBase to create listeners and start listening for messages.
69 serviceHost.Open();
71 // The service can now be accessed.
72 Console.WriteLine("The service is ready.");
73 Console.WriteLine("Press <ENTER> to terminate service.");
74 Console.WriteLine();
75 Console.ReadLine();