2 // Copyright (c) Microsoft Corporation. All Rights Reserved.
5 using System
.ServiceModel
;
6 using System
.ServiceModel
.Description
;
7 using System
.Collections
.ObjectModel
;
8 using System
.Security
.Cryptography
.X509Certificates
;
9 using System
.ServiceModel
.Channels
;
10 using System
.ServiceModel
.Security
;
12 namespace Microsoft
.ServiceModel
.Samples
14 //The service contract is defined in generatedCalculatorService.cs, generated from the service by the svcutil tool.
16 //Client implementation code.
21 // Create a proxy with given client endpoint configuration
22 CalculatorClient client
= new CalculatorClient();
24 // set the certificate on the client
25 client
.ClientCredentials
.ClientCertificate
.SetCertificate(StoreLocation
.CurrentUser
, StoreName
.My
,
26 X509FindType
.FindBySubjectName
, "client.com");
27 client
.ClientCredentials
.ServiceCertificate
.Authentication
.CertificateValidationMode
= X509CertificateValidationMode
.PeerOrChainTrust
;
30 // Call the GetCallerIdentity service operation
31 Console
.WriteLine(client
.GetCallerIdentity());
33 // Call the Add service operation.
34 double value1
= 100.00D
;
35 double value2
= 15.99D
;
36 double result
= client
.Add(value1
, value2
);
37 Console
.WriteLine("Add({0},{1}) = {2}", value1
, value2
, result
);
40 // Call the Subtract service operation.
43 result
= client
.Subtract(value1
, value2
);
44 Console
.WriteLine("Subtract({0},{1}) = {2}", value1
, value2
, result
);
46 // Call the Multiply service operation.
49 result
= client
.Multiply(value1
, value2
);
50 Console
.WriteLine("Multiply({0},{1}) = {2}", value1
, value2
, result
);
52 // Call the Divide service operation.
55 result
= client
.Divide(value1
, value2
);
56 Console
.WriteLine("Divide({0},{1}) = {2}", value1
, value2
, result
);
58 //Closing the client gracefully closes the connection and cleans up resources
62 Console
.WriteLine("Press <ENTER> to terminate client.");