Example #1
0
        static void Main(string[] args)
        {
            PermissionCertificatePolicy.Enact("CN=HTTPS-Server");

            using (ServiceReference1.CalculatorClient service = new ServiceReference1.CalculatorClient("BasicHttpBinding_ICalculator"))
            {
                service.ClientCredentials.UserName.UserName = "******";
                service.ClientCredentials.UserName.Password = "******";

                Console.WriteLine("调用 WCF 服务 ( {0} )  开始!", "BasicHttpBinding_ICalculator");

                Console.WriteLine("service.Add(1, 2) = {0}", service.Add(1, 2));
                Console.WriteLine("service.Sub(2, 3) = {0}", service.Sub(2, 3));
                Console.WriteLine("service.Mul(3, 4) = {0}", service.Mul(3, 4));

                ServiceReference1.DivResult divResult = service.Div(5, 2);
                Console.WriteLine("service.Div(5, 2) = {0} 余 {1} ", divResult.DivData, divResult.ModData);

                Console.WriteLine("调用 WCF 服务 ( {0} )  结束!", "BasicHttpBinding_ICalculator");

                Console.WriteLine();
            }

            Console.WriteLine("按回车键结束!");

            Console.ReadLine();
        }
Example #2
0
        public static void CallFromWCF()
        {
            ServiceReference1.CalculatorClient client = new ServiceReference1.CalculatorClient();
            client.ClientCredentials.UserName.UserName = "******";
            client.ClientCredentials.UserName.Password = "******";
            client.Endpoint.Behaviors.Add(new InspectorBehavior());
            double result= client.Add(1,2);

            Console.WriteLine(result.ToString());
        }
Example #3
0
        private void InitializeClient()
        {
            if (this.client == null)
            {
                this.client = new ServiceReference1.CalculatorClient();
                BasicHttpBinding binding = this.client.Endpoint.Binding as BasicHttpBinding;
                binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

                //client.ClientCredentials.UserName.UserName = "******";
                //client.ClientCredentials.UserName.Password = "******";

                this.client.Endpoint.Behaviors.Remove<ClientCredentials>();
                this.client.Endpoint.Behaviors.Add(new ClientCredentialsEx(this));
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press enter to call the service");
            Console.ReadLine();

            var proxy = new ServiceReference1.CalculatorClient("BasicHttpEndpoint");
            proxy.ClientCredentials.UserName.UserName = "******";
            proxy.ClientCredentials.UserName.Password = "******";

            var arguments = new ServiceReference1.Arguments();
            arguments.Arg1 = 1;
            arguments.Arg2 = 2;

            var result = proxy.Add(arguments);

            Console.WriteLine("Result: "+ result.Value);
            Console.WriteLine("Press enter to close the application :)");
            Console.ReadLine();
        }
Example #5
0
        static void Main()
        {
            // Create a client
            ServiceReference1.CalculatorClient client = new ServiceReference1.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();
        }
Example #6
0
        public static void WCFServiceConsume()
        {
            try
            {
                Console.WriteLine("Windows-Hosting a WCF Service in Console Application\n");
                Console.WriteLine("-------------------------------------------------\n");
                Console.WriteLine("Enter first integer number : ");
                int number1 = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("Enter second integer number : ");
                int number2 = Convert.ToInt32(Console.ReadLine());

                ServiceReference1.CalculatorClient cal = new ServiceReference1.CalculatorClient();

                try
                {
                    int addition = cal.Addition(number1, number2);
                    Console.WriteLine("Addition Result : " + addition);
                }
                catch (FaultException<ExceptionMessage> exceptionFromService)
                {
                    Console.WriteLine("Addition Service Error : " + exceptionFromService.Detail.errorMessageOfAction);
                }

                try
                {
                    int subtraction = cal.Subtraction(number1, number2);
                    Console.WriteLine("Subtraction Result : " + subtraction);
                }
                catch (FaultException<ExceptionMessage> exceptionFromService)
                {
                    Console.WriteLine("Subtraction Service Error : " + exceptionFromService.Detail.errorMessageOfAction);
                }

                try
                {
                    int multiplication = cal.Multiplication(number1, number2);
                    Console.WriteLine("Multiplication Result : " + multiplication);
                }
                catch (FaultException<ExceptionMessage> exceptionFromService)
                {
                    Console.WriteLine("Multiplication Service Error : " + exceptionFromService.Detail.errorMessageOfAction);
                }

                try
                {
                    int division = cal.Division(number1, number2);
                    Console.WriteLine("Division Result : " + division);
                }
                catch (FaultException<ExceptionMessage> exceptionFromService)
                {
                    Console.WriteLine("Division Service Error : " + exceptionFromService.Detail.errorMessageOfAction);
                }
                Console.WriteLine("*********************************\n");
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
                Console.ReadKey();
            }
            finally
            {
                ConsoleClose();
            }
        }