示例#1
0
        public static void CallService(string endpointName)
        {
            CalculatorClient client = new CalculatorClient(endpointName);

            Console.WriteLine("Calling Endpoint: {0}", endpointName);
            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
            Console.WriteLine();

            client.Close();
        }
示例#2
0
        static void DoCalculations(CalculatorClient client)
        {
            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
        }
示例#3
0
        static void Main(string[] args)
        {
            CalculatorClient client = new CalculatorClient();

            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#4
0
        static void Main()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient("NetTcpBinding_ICalculator");

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#5
0
        static void Main()
        {
            //Create a proxy with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);
            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#6
0
        static void Main()
        {
            // Create a client with Certificate endpoint configuration
            CalculatorClient client = new CalculatorClient("Certificate");

            try
            {
                client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "alice");

                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = client.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = client.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
                client.Close();
            }
            catch (TimeoutException e)
            {
                Console.WriteLine("Call timed out : {0}", e.Message);
                client.Abort();
            }
            catch (CommunicationException e)
            {
                Console.WriteLine("Call failed : {0}", e.Message);
                client.Abort();
            }
            catch (Exception e)
            {
                Console.WriteLine("Call failed : {0}", e.Message);
                client.Abort();
            }



            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#7
0
        public double Subtract(double n1, double n2)
        {
            CalculatorClient client = new CalculatorClient();

            client.ClientCredentials.UserName.UserName = ServiceSecurityContext.Current.PrimaryIdentity.Name;
            double result = client.Subtract(n1, n2);

            client.Close();
            return(result);
        }
示例#8
0
        /// <summary>
        /// Makes calls to the specified endpoint name in app.config
        /// </summary>
        /// <param name="endpointName">The endpoint to use from app.config</param>
        private static void CallEndpoint(string endpointName)
        {
            Console.WriteLine("\nCalling endpoint {0}\n", endpointName);

            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient(endpointName);

            // Create new credentials class
            SamlClientCredentials samlCC = new SamlClientCredentials();

            // Set the client certificate. This is the cert that will be used to sign the SAML token in the symmetric proof key case
            samlCC.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My, X509FindType.FindBySubjectName, "Alice");

            // Set the service certificate. This is the cert that will be used to encrypt the proof key in the symmetric proof key case
            samlCC.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser, StoreName.TrustedPeople, X509FindType.FindBySubjectName, "localhost");

            // Create some claims to put in the SAML assertion
            IList <Claim> claims = new List <Claim>();

            claims.Add(Claim.CreateNameClaim(samlCC.ClientCertificate.Certificate.Subject));
            ClaimSet claimset = new DefaultClaimSet(claims);

            samlCC.Claims = claimset;

            // set new credentials
            client.ChannelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
            client.ChannelFactory.Endpoint.Behaviors.Add(samlCC);

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            client.Close();
        }
示例#9
0
        static void Main()
        {
            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            try
            {
                // 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);

                // 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);

                //Closing the client gracefully closes the connection and cleans up resources
                client.Close();
            }
            catch (FaultException <MathFault> e)
            {
                Console.WriteLine("FaultException<MathFault>: Math fault while doing " + e.Detail.Operation + ". Problem: " + e.Detail.ProblemType);
                client.Abort();
            }
            catch (FaultException e)
            {
                Console.WriteLine("Unknown FaultException: " + e.GetType().Name + " - " + e.Message);
                client.Abort();
            }
            catch (Exception e)
            {
                Console.WriteLine("EXCEPTION: " + e.GetType().Name + " - " + e.Message);
                client.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#10
0
        static void Main()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient();

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            // Call the Sum service operation.
            int[] values = { 1, 2, 3, 4, 5 };

            using (new OperationContextScope(client.InnerChannel))
            {
                Message request = Message.CreateMessage(OperationContext.Current.OutgoingMessageHeaders.MessageVersion,
                                                        "http://Microsoft.ServiceModel.Samples/ICalculator/Sum", values);

                Message reply = client.Sum(request);

                int sum = reply.GetBody <int>();
                Console.WriteLine("Sum(1,2,3,4,5) = {0}", sum);
            }

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#11
0
        static void Main()
        {
            // Create a WCF client object.
            CalculatorClient wcfClient = new CalculatorClient();

            try
            {
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = wcfClient.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = wcfClient.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = wcfClient.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = wcfClient.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                // Closing the client gracefully closes the connection and cleans up resources.
                wcfClient.Close();
            }
            catch (TimeoutException timeout)
            {
                Console.WriteLine(timeout.Message);
                Console.ReadLine();
                wcfClient.Abort();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine(commProblem.Message);
                Console.ReadLine();
                wcfClient.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#12
0
        static void Main()
        {
            // Create a wcfClient with the given client endpoint configuration.
            CalculatorClient wcfClient = new CalculatorClient();

            try
            {
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = wcfClient.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = wcfClient.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = wcfClient.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = wcfClient.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                wcfClient.Close();
            }
            catch (TimeoutException timeProblem)
            {
                Console.WriteLine("The service operation timed out. " + timeProblem.Message);
                Console.ReadLine();
                wcfClient.Abort();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
                Console.ReadLine();
                wcfClient.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#13
0
        static void CallWcfService()
        {
            EndpointAddress address = new EndpointAddress(new Uri("http://localhost:8000/servicemodelsamples/service"),
                                                          EndpointIdentity.CreateDnsIdentity("localhost"));

            WseHttpBinding binding = new WseHttpBinding();

            binding.SecurityAssertion        = WseSecurityAssertion.AnonymousForCertificate;
            binding.EstablishSecurityContext = true;
            binding.RequireDerivedKeys       = true;
            binding.MessageProtectionOrder   = MessageProtectionOrder.SignBeforeEncrypt;

            // Use the calculator client in generatedClient.cs
            CalculatorClient client = new CalculatorClient(binding, address);

            client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
                StoreLocation.CurrentUser,
                StoreName.TrustedPeople,
                X509FindType.FindBySubjectName,
                "localhost");
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#14
0
        static void Main()
        {
            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            // set new credentials
            client.ChannelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
            client.ChannelFactory.Endpoint.Behaviors.Add(new MyUserNameClientCredentials());

            /*
             * Setting the CertificateValidationMode to PeerOrChainTrust means that if the certificate
             * is in the Trusted People store, then it will be trusted without performing a
             * validation of the certificate's issuer chain. This setting is used here for convenience so that the
             * sample can be run without having to have certificates issued by a certificate authority (CA).
             * This setting is less secure than the default, ChainTrust. The security implications of this
             * setting should be carefully considered before using PeerOrChainTrust in production code.
             */
            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#15
0
        static void Main()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient();

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            Console.WriteLine();

            Console.WriteLine("Client - endpoint:  " + client.Endpoint.Address);
            Console.WriteLine("Client - binding:  " + client.Endpoint.Binding.Name);
            Console.WriteLine("Client - contract: " + client.Endpoint.Contract.Name);

            IClientChannel channel = client.InnerChannel;

            Console.WriteLine("Client channel - state: " + channel.State);
            Console.WriteLine("Client channel - session identifier: " + channel.SessionId);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#16
0
        static void Main()
        {
            // Create a proxy with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            // set the certificate on the client
            client.ClientCredentials.ClientCertificate.SetCertificate(StoreLocation.CurrentUser, StoreName.My,
                                                                      X509FindType.FindBySubjectName, "client.com");
            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;


            // Call the GetCallerIdentity service operation
            Console.WriteLine(client.GetCallerIdentity());

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);


            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#17
0
        static void Main()
        {
            //Specify the binding to be used for the client.
            BasicHttpBinding binding = new BasicHttpBinding();

            //Specify the address to be used for the client.
            EndpointAddress address =
                new EndpointAddress("http://localhost/servicemodelsamples/service.svc");


            // Create a client that is configured with this address and binding.
            CalculatorClient client = new CalculatorClient(binding, address);

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#18
0
        static void DoWork()
        {
            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            Random rand = new Random();

            while (!flag)
            {
                // Call the Add service operation.
                double value1 = (double)rand.Next(0, 5);
                double value2 = (double)rand.Next(0, 5);
                double result;

                switch (rand.Next(0, 4))
                {
                case (0):
                    IncrementCounter();
                    result = client.Add(value1, value2);
                    Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
                    break;

                case (1):
                    result = client.Subtract(value1, value2);
                    Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
                    break;

                case (2):
                    result = client.Multiply(value1, value2);
                    Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);
                    break;

                case (3):
                    result = client.Divide(value1, value2);
                    Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
                    break;
                }

                Thread.Sleep(500);
            }

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();
        }
示例#19
0
        static void Main()
        {
            // Create a client
            CalculatorClient client = new CalculatorClient();

            // Create a transaction scope with the default isolation level of Serializable
            using (TransactionScope tx = new TransactionScope())
            {
                Console.WriteLine("Starting transaction");

                // Call the Add service operation.
                double value = 100.00D;
                Console.WriteLine("  Adding {0}, running total={1}",
                                  value, client.Add(value));

                // Call the Subtract service operation.
                value = 45.00D;
                Console.WriteLine("  Subtracting {0}, running total={1}",
                                  value, client.Subtract(value));

                // Call the Multiply service operation.
                value = 9.00D;
                Console.WriteLine("  Multiplying by {0}, running total={1}",
                                  value, client.Multiply(value));

                // Call the Divide service operation.
                value = 15.00D;
                Console.WriteLine("  Dividing by {0}, running total={1}",
                                  value, client.Divide(value));

                Console.WriteLine("  Completing transaction");
                tx.Complete();
            }

            Console.WriteLine("Transaction committed");

            // Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#20
0
        static void Main()
        {
            // WARNING: This code is only needed for test certificates such as those created by makecert. It is
            // not recommended for production code.
            PermissiveCertificatePolicy.Enact("CN=ServiceModelSamples-HTTPS-Server");

            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#21
0
        static void Main()
        {
            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            // Call the GetCallerIdentity operation
            Console.WriteLine("IsCallerAnonymous returned: {0}", client.IsCallerAnonymous());

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#22
0
        static void Main(string[] args)
        {
            CalculatorClient client = new CalculatorClient();

            //X509Certificate2 cert = new X509Certificate2("c:\\MyClientCert.pfx", "password", X509KeyStorageFlags.DefaultKeySet);
            //client.ClientCredentials.ClientCertificate.Certificate = cert;
            //client.ClientCredentials.UserName.UserName = "******";
            //client.ClientCredentials.UserName.Password = "******";

            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#23
0
        public static void CallServiceCustomClientIdentity(string endpointName)
        {
            // Create a custom binding that sets a custom IdentityVerifier.
            Binding customSecurityBinding = CreateCustomSecurityBinding();
            // Call the service with DNS identity, setting a custom EndpointIdentity that checks that the certificate
            // returned from the service contains an organization name of Contoso in the subject name; that is, O=Contoso.
            EndpointAddress serviceAddress = new EndpointAddress(new Uri("http://localhost:8003/servicemodelsamples/service/dnsidentity"),
                                                                 new OrgEndpointIdentity("O=Contoso"));

            //<snippet4>
            using (CalculatorClient client = new CalculatorClient(customSecurityBinding, serviceAddress))
            {
                //</snippet4>
                client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(StoreLocation.CurrentUser,
                                                                                  StoreName.TrustedPeople,
                                                                                  X509FindType.FindBySubjectDistinguishedName,
                                                                                  "CN=identity.com, O=Contoso");
                // Setting the certificateValidationMode to PeerOrChainTrust means that if the certificate
                // is in the user's Trusted People store, then it will be trusted without performing a
                // validation of the certificate's issuer chain. This setting is used here for convenience so that the
                // sample can be run without having to have certificates issued by a certificate authority (CA).
                // This setting is less secure than the default, ChainTrust. The security implications of this
                // setting should be carefully considered before using PeerOrChainTrust in production code.
                client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.PeerOrChainTrust;

                Console.WriteLine("Calling Endpoint: {0}", endpointName);
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
                Console.WriteLine();

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = client.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);
            }
        }
示例#24
0
        static void Main(string[] args)
        {
            // Create a client
            // Since multiple endpoints exist, an endpoint is chosen as the
            // constructor parameter.
            CalculatorClient client = new CalculatorClient("CalcServiceSEP1");

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#25
0
        static void Main()
        {
            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            client.ClientCredentials.Windows.AllowedImpersonationLevel = TokenImpersonationLevel.Impersonation;
            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#26
0
        static void Main()
        {
            // Create a client
            // Specify CalculatorEndpoint1 through CalculatorEndpoint4 to try various endpoints.
            CalculatorClient client = new CalculatorClient("CalculatorEndpoint1");

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#27
0
        static void InvokeClient(string configurationName)
        {
            Console.WriteLine("Using {0} endpoint.", configurationName);

            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient(configurationName);

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
        }
示例#28
0
        static void Main()
        {
            // Create a proxy with default client endpoint configuration.
            CalculatorClient client = new CalculatorClient();

            // Add
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Subtract
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Multiply
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Divide
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            //Closing the client gracefully closes the connection and cleans up resources
            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#29
0
        static void Main()
        {
            {
                // <Snippet1>
                // Configure custom certificate validation.
                ClientCredentials creds = new ClientCredentials();
                creds.ServiceCertificate.Authentication.CertificateValidationMode
                    = X509CertificateValidationMode.Custom;
                creds.ServiceCertificate.Authentication.CustomCertificateValidator
                    = new MyCertificateValidator();
                // </Snippet1>
            }
            {
                // <Snippet2>
                ClientCredentials creds = new ClientCredentials();

                // Configure chain trust.

                creds.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.ChainTrust;

                creds.ServiceCertificate.Authentication.RevocationMode =
                    X509RevocationMode.NoCheck;
                // </Snippet2>
            }
            {
                // <Snippet3>
                ClientCredentials creds = new ClientCredentials();

                // Configure chain trust.
                creds.ServiceCertificate.Authentication.CertificateValidationMode
                    = X509CertificateValidationMode.ChainTrust;
                creds.ServiceCertificate.Authentication.TrustedStoreLocation
                    = StoreLocation.LocalMachine;
                // </Snippet3>
            }

            {
                // <Snippet4>
                ClientCredentials clientCreds =
                    new ClientCredentials();
                Console.WriteLine(
                    clientCreds.ServiceCertificate.Authentication);
                // </Snippet4>
            }

            // Create a client with given client endpoint configuration
            CalculatorClient wcfClient = new CalculatorClient();

            try
            {
                // set new credentials
                wcfClient.ChannelFactory.Endpoint.Behaviors.Remove(typeof(ClientCredentials));
                wcfClient.ChannelFactory.Endpoint.Behaviors.Add(new MyUserNameClientCredentials());

                /*
                 * Setting the CertificateValidationMode to PeerOrChainTrust means that if the certificate
                 * is in the Trusted People store, then it will be trusted without performing a
                 * validation of the certificate's issuer chain. This setting is used here for convenience so that the
                 * sample can be run without having to have certificates issued by a certificate authority (CA).
                 * This setting is less secure than the default, ChainTrust. The security implications of this
                 * setting should be carefully considered before using PeerOrChainTrust in production code.
                 */
                wcfClient.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.PeerOrChainTrust;
                // <Snippet0>
                ClientCredentials creds = new ClientCredentials();
                // Configure peer trust.
                creds.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.PeerTrust;

                // Configure chain trust.
                creds.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.ChainTrust;

                // Configure custom certificate validation.
                creds.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.Custom;
                creds.ServiceCertificate.Authentication.CustomCertificateValidator =
                    new MyCertificateValidator();
                // </Snippet0>
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = wcfClient.Add(value1, value2);
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = wcfClient.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = wcfClient.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = wcfClient.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);
                wcfClient.Close();
            }
            catch (TimeoutException timeProblem)
            {
                Console.WriteLine("The service operation timed out. " + timeProblem.Message);
                Console.ReadLine();
                wcfClient.Abort();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
                Console.ReadLine();
                wcfClient.Abort();
            }

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
示例#30
0
        static void Main()
        {
            Console.WriteLine("Username authentication required.");
            Console.WriteLine(" Please enter a valid domain email address:");
            string username = Console.ReadLine();

            Console.WriteLine("   Enter password:"******"";
            ConsoleKeyInfo info     = Console.ReadKey(true);

            while (info.Key != ConsoleKey.Enter)
            {
                if (info.Key != ConsoleKey.Backspace)
                {
                    password += info.KeyChar;
                    info      = Console.ReadKey(true);
                }
                else if (info.Key == ConsoleKey.Backspace)
                {
                    if (password != "")
                    {
                        password = password.Substring(0, password.Length - 1);
                    }
                    info = Console.ReadKey(true);
                }
            }

            for (int i = 0; i < password.Length; i++)
            {
                Console.Write("*");
            }

            Console.WriteLine();

            // Create a client with given client endpoint configuration
            CalculatorClient client = new CalculatorClient();

            client.ClientCredentials.UserName.UserName = username;
            client.ClientCredentials.UserName.Password = password;

            /*
             * Setting the CertificateValidationMode to PeerOrChainTrust means that if the certificate
             * is in the Trusted People store, then it will be trusted without performing a
             * validation of the certificate's issuer chain. This setting is used here for convenience so that the
             * sample can be run without having to have certificates issued by a certificate authority (CA).
             * This setting is less secure than the default, ChainTrust. The security implications of this
             * setting should be carefully considered before using PeerOrChainTrust in production code.
             */
            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.PeerOrChainTrust;
            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = client.Add(value1, value2);

            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

            // Call the Subtract service operation.
            value1 = 145.00D;
            value2 = 76.54D;
            result = client.Subtract(value1, value2);
            Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

            // Call the Multiply service operation.
            value1 = 9.00D;
            value2 = 81.25D;
            result = client.Multiply(value1, value2);
            Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

            // Call the Divide service operation.
            value1 = 22.00D;
            value2 = 7.00D;
            result = client.Divide(value1, value2);
            Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

            client.Close();

            Console.WriteLine();
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }