Пример #1
0
        private static void Evaluate(string strServer, string strBinding, int nPort, string strOper, int dblVal1, int dblVal2)
        {
            ChannelFactory <MathService> channelFactory = null;
            EndpointAddress ep = null;

            //string strEPAdr = "http://" + strServer + ":" + nPort.ToString() + "/MathService";
            string strEPAdr = @"http://*****:*****@"http://localhost:9001/MathService";
                    ep = new EndpointAddress(strEPAdr);
                    BasicHttpBinding httpb = new BasicHttpBinding();
                    channelFactory = new ChannelFactory <MathService>(httpb);
                    break;
                }

                MathService mathSvcObj = channelFactory.CreateChannel(ep);
                int         dblResult  = 0;
                switch (strOper)
                {
                case "ADD": dblResult = mathSvcObj.AddNumber(dblVal1, dblVal2); break;
                    //case "SUB": dblResult = mathSvcObj.SubtractNumber(dblVal1, dblVal2); break;
                    //case "MUL": dblResult = mathSvcObj.MultiplyNumber(dblVal1, dblVal2); break;
                    //case "DIV": dblResult = mathSvcObj.DivideNumber(dblVal1, dblVal2); break;
                }

                Console.WriteLine("Operation {0} ", strOper);
                //Console.WriteLine("Operand 1 {0} ", dblVal1.ToString("F2"));
                //Console.WriteLine("Operand 2 {0} ", dblVal2.ToString("F2"));
                //Console.WriteLine("Result {0} ", dblResult.ToString("F2"));
                channelFactory.Close();
            }
            catch (Exception eX)
            {
                Console.WriteLine("Error while performing operation [" + eX.Message + "] \n\n Inner Exception [" + eX.InnerException + "]");
            }
        }