-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (59 loc) · 2.02 KB
/
Program.cs
File metadata and controls
69 lines (59 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//The service contract is defined using Connected Service "WCF Web Service", generated from the service by the dotnet svcutil tool.
//Client implementation code.
using System.ServiceModel;
// Create a client with given client endpoint configuration
CalculatorServiceClient client = new CalculatorServiceClient();
// Call the Add service operation
int value1 = 15;
int value2 = 3;
int result = client.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
// Call the Subtract service operation
value1 = 145;
value2 = 76;
result = client.Subtract(value1, value2);
Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
// Call the Multiply service operation
value1 = 9;
value2 = 81;
result = client.Multiply(value1, value2);
Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
try
{
Console.WriteLine("Forcing an error in Divide");
// Call the Divide service operation - trigger a divide by zero error
value1 = 22;
value2 = 0;
result = client.Divide(value1, value2);
Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
}
catch (FaultException e)
{
Console.WriteLine("FaultException: " + e.GetType().Name + " - " + e.Message);
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.GetType().Name + " - " + e.Message);
}
try
{
// Call the Factorial service operation - trigger an overflow error
Console.WriteLine("Forcing an error in Factorial");
value1 = 0;
result = client.Factorial(value1);
Console.WriteLine("Factorial({0}) = {1}", value1, result);
}
catch (FaultException e)
{
Console.WriteLine("FaultException: " + e.GetType().Name + " - " + e.Message);
}
catch (Exception e)
{
Console.WriteLine("Exception: " + e.GetType().Name + " - " + e.Message);
}
client.Close();
Console.WriteLine();
Console.WriteLine("Press <ENTER> to terminate client.");
Console.ReadLine();