Beispiel #1
0
        static void Main()
        {
            var endpoints = MetadataResolver.Resolve(typeof(ICalculatorService),
                                                    new EndpointAddress("http://localhost:8088/CalculatorService/mex"));

            Console.WriteLine("Welcome in WcfSample Hosting client \n\t#Client Base Sample");
            Console.ReadLine();

            var entity = new CalculatorEntity
            {
                FirstValue = 3.33,
                Calculation = Calculation.Add,
                SecondValue = 4.44
            };

            Console.WriteLine("\n\tMex Sample.");
            Console.WriteLine();

            var clientSelfHosting = new CalculatorServiceClient(endpoints[0].Binding, endpoints[0].Address);
            var result = clientSelfHosting.Invoke(clientSelfHosting.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result.Output);

            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
Beispiel #2
0
        private static void ExecuteSelfHostedSample(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tSelf-hosting sample.");
            Console.WriteLine();

            var clientSelfHosting = new CalculatorServiceClient("WSHttpBinding_CalculatorService_SelfHosted");
            ServiceInvoker.ServiceResult<double> result = clientSelfHosting.Invoke(clientSelfHosting.Eval, entity);
            Console.WriteLine(OutputInfo, result);
        }
Beispiel #3
0
        private static void ExecuteDynamicProxy(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tService - using dynamic proxy");
            Console.WriteLine();

            var serviceResult =
                ServiceProxyFactory<ICalculatorService>.Create("WSHttpBinding_CalculatorService_IIS").Invoke(x => x.Eval(entity));
            Console.WriteLine(OutputInfo, serviceResult);
        }
Beispiel #4
0
        private static void ExecuteSelfHostedSample(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tSelf-hosting sample.");
            Console.WriteLine();

            var selfHostServiceClient = new CalculatorServiceSelfHostReference.CalculatorServiceClient("WSHttpBinding_CalculatorService1");
            var result = selfHostServiceClient.Invoke(selfHostServiceClient.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result);
        }
Beispiel #5
0
        private static void ExecuteIISSample(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tIIS Sample.");
            Console.WriteLine();

            var iisServiceClient = new CalculatorServiceClient("WSHttpBinding_CalculatorService");
            var result = iisServiceClient.Invoke(iisServiceClient.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result);
        }
Beispiel #6
0
        private static void SelfHostedSample(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tSelf-hosting sample.");
            Console.WriteLine();

            var factorySelfHosted = new ChannelFactory<ICalculatorServiceChannel>("WSHttpBinding_CalculatorService_SelfHosted");
            var channelSelfHosted = factorySelfHosted.CreateChannel();

            ServiceInvoker.ServiceResult<double> result = channelSelfHosted.Invoke(channelSelfHosted.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result);
        }
Beispiel #7
0
        private static void ExecuteIISSample(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tIIS Sample.");
            Console.WriteLine();

            var factoryIIS = new ChannelFactory<ICalculatorServiceChannel>("WSHttpBinding_CalculatorService_IIS");
            var channelIIS = factoryIIS.CreateChannel();

            var result = channelIIS.Invoke(channelIIS.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result);
        }
Beispiel #8
0
        private static void ExecuteDivideByZeroSample(CalculatorEntity entity)
        {
            Console.WriteLine("\tSelf-hosting sample - divide by zero");
            Console.WriteLine();

            CalculatorServiceClient clientSelfHosting = new CalculatorServiceClient("WSHttpBinding_CalculatorService_SelfHosted");
            entity.Calculation = Calculation.Divide;
            entity.SecondValue = 0;
            ServiceInvoker.ServiceResult<double> result = clientSelfHosting.Invoke(clientSelfHosting.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result.Output);
        }
Beispiel #9
0
        private static void DivideByZeroSample(CalculatorEntity entity)
        {
            Console.WriteLine("\n\tSelf-hosting sample - divide by zero");
            Console.WriteLine();

            var factorySelfHosted = new ChannelFactory<ICalculatorServiceChannel>("WSHttpBinding_CalculatorService_SelfHosted");
            ICalculatorServiceChannel channelSelfHosted = factorySelfHosted.CreateChannel();
            entity.Calculation = Calculation.Divide;
            entity.SecondValue = 0;
            ServiceInvoker.ServiceResult<double> result = channelSelfHosted.Invoke(channelSelfHosted.Eval, entity);

            if (result.Success)
                Console.WriteLine(OutputInfo, result.Output);
        }
Beispiel #10
0
        static void Main()
        {
            Console.WriteLine("Welcome in WcfSample Hosting client \n\t#Service Reference Sample");
            Console.ReadLine();

            var entity = new CalculatorEntity {
                                                  FirstValue = 3.33,
                                                  Calculation = Calculation.Add,
                                                  SecondValue = 4.44
                                              };

            ExecuteIISSample(entity);
            ExecuteSelfHostedSample(entity);
            ExecuteDivideByZero(entity);

            Console.WriteLine("Press [Enter] to exit...");
            Console.ReadLine();
        }
        public double Eval(CalculatorEntity entity)
        {
            switch (entity.Calculation)
            {
                case Calculation.Add:
                    return entity.FirstValue + entity.SecondValue;
                case Calculation.Subtract:
                    return entity.FirstValue - entity.SecondValue;
                case Calculation.Multiply:
                    return entity.FirstValue * entity.SecondValue;
                case Calculation.Divide:
                    if (entity.SecondValue == 0)
                        throw new FaultException("You cannot divide by 0.");

                    return entity.FirstValue / entity.SecondValue;
                case Calculation.Square:
                    return entity.FirstValue * entity.FirstValue;
                case Calculation.Sqrt:
                    return Math.Sqrt(entity.FirstValue);
            }

            return 0.0;
        }