added samples
[windows-sources.git] / sdk / samples / WCFSamples / TechnologySamples / Extensibility / Security / SamlTokenProvider / CS / client / client.cs
blobf088aa42ccf1063565999aa4d3f79e0ebb41bdf5
1 //-----------------------------------------------------------------------------
2 // Copyright (c) Microsoft Corporation. All rights reserved.
3 //-----------------------------------------------------------------------------
4 using System;
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.
20 class Client
22 static void Main()
24 // Call the two different endpoints
25 CallEndpoint("CalcSymm");
26 CallEndpoint("CalcAsymm");
28 Console.WriteLine();
29 Console.WriteLine("Press <ENTER> to terminate client.");
30 Console.ReadLine();
33 /// <summary>
34 /// Makes calls to the specified endpoint name in app.config
35 /// </summary>
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.
70 value1 = 145.00D;
71 value2 = 76.54D;
72 result = client.Subtract(value1, value2);
73 Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
75 // Call the Multiply service operation.
76 value1 = 9.00D;
77 value2 = 81.25D;
78 result = client.Multiply(value1, value2);
79 Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
81 // Call the Divide service operation.
82 value1 = 22.00D;
83 value2 = 7.00D;
84 result = client.Divide(value1, value2);
85 Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
87 client.Close();