WCF代码创建通道,访问并执行服务方法

 EndpointAddress address = new EndpointAddress("http://localhost/servicemodelsamples/service.svc");
            WSHttpBinding binding = new WSHttpBinding();
            ChannelFactory<ICalculator> factory = new ChannelFactory<ICalculator>(binding, address);
            ICalculator channel = factory.CreateChannel();

            // Call the Add service operation.
            double value1 = 100.00D;
            double value2 = 15.99D;
            double result = channel.Add(value1, value2);
            Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
((IChannel)channel).Close();
posted @ 2012-05-02 14:22  王宏磊@中国  阅读(425)  评论(0编辑  收藏  举报