1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //-----------------------------------------------------------------------------
6 using System
.Collections
.Generic
;
8 using System
.IdentityModel
.Claims
;
10 using System
.Security
.Cryptography
.X509Certificates
;
12 using System
.ServiceModel
;
13 using System
.ServiceModel
.Description
;
15 namespace Microsoft
.ServiceModel
.Samples
17 //The service contract is defined in generatedClient.cs, generated from the service by the svcutil tool.
19 //Client implementation code.
24 // Call the two different endpoints
25 CallEndpoint("CalcSymm");
26 CallEndpoint("CalcAsymm");
29 Console
.WriteLine("Press <ENTER> to terminate client.");
34 /// Makes calls to the specified endpoint name in app.config
36 /// <param name="endpointName">The endpoint to use from app.config</param>
37 private static void CallEndpoint(string endpointName
)
39 Console
.WriteLine("\nCalling endpoint {0}\n", endpointName
);
41 // Create a client with given client endpoint configuration
42 CalculatorClient client
= new CalculatorClient(endpointName
);
44 // Create new credentials class
45 SamlClientCredentials samlCC
= new SamlClientCredentials();
47 // Set the client certificate. This is the cert that will be used to sign the SAML token in the symmetric proof key case
48 samlCC
.ClientCertificate
.SetCertificate(StoreLocation
.CurrentUser
, StoreName
.My
, X509FindType
.FindBySubjectName
, "Alice");
50 // Set the service certificate. This is the cert that will be used to encrypt the proof key in the symmetric proof key case
51 samlCC
.ServiceCertificate
.SetDefaultCertificate(StoreLocation
.CurrentUser
, StoreName
.TrustedPeople
, X509FindType
.FindBySubjectName
, "localhost");
53 // Create some claims to put in the SAML assertion
54 IList
<Claim
> claims
= new List
<Claim
>();
55 claims
.Add(Claim
.CreateNameClaim(samlCC
.ClientCertificate
.Certificate
.Subject
));
56 ClaimSet claimset
= new DefaultClaimSet(claims
);
57 samlCC
.Claims
= claimset
;
59 // set new credentials
60 client
.ChannelFactory
.Endpoint
.Behaviors
.Remove(typeof(ClientCredentials
));
61 client
.ChannelFactory
.Endpoint
.Behaviors
.Add(samlCC
);
63 // Call the Add service operation.
64 double value1
= 100.00D
;
65 double value2
= 15.99D
;
66 double result
= client
.Add(value1
, value2
);
67 Console
.WriteLine("Add({0},{1}) = {2}", value1
, value2
, result
);
69 // Call the Subtract service operation.
72 result
= client
.Subtract(value1
, value2
);
73 Console
.WriteLine("Subtract({0},{1}) = {2}", value1
, value2
, result
);
75 // Call the Multiply service operation.
78 result
= client
.Multiply(value1
, value2
);
79 Console
.WriteLine("Multiply({0},{1}) = {2}", value1
, value2
, result
);
81 // Call the Divide service operation.
84 result
= client
.Divide(value1
, value2
);
85 Console
.WriteLine("Divide({0},{1}) = {2}", value1
, value2
, result
);