WCF创建客户端的方法

1、svcutil.exe工具创建客户端代理类

     打开Visual Studio命令提示 svcutil.exe /out:c:\ClientCode.cs /config:c:\app.config http://localhost:8000/Services/service.svc

2、代码编写基础通道创建客户端代理类

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

3、客户端通过添加Web添加引用

posted @ 2012-05-02 14:38  王宏磊@中国  阅读(283)  评论(0编辑  收藏  举报