WCF客户端引用服务 代码

方法1:

复制代码

            using (ChannelFactory<ICommonService> channelFactory = new ChannelFactory<ICommonService>(new BasicHttpBinding(), "http://127.0.0.1/SystemSecurityService.svc"))
            {
                ICommonService proxy = channelFactory.CreateChannel();
                return proxy;
            }

复制代码

方法2:

            BasicHttpsBinding BINDING = new BasicHttpsBinding();
            return new Service1Client(BINDING, new EndpointAddress("http://127.0.0.1/Service1.svc"));//构建WCF客户端实例

方法3:

            WSHttpBinding BINDING = new WSHttpBinding();
            SoapClientConfig.ReadBindingConfig(BINDING, "WSHttpBinding_ICommonService");//从配置文件(app.config)读取配置。            
            string endpoint = SoapClientConfig.GetSoapRemoteAddress("WSHttpBinding_ICommonService");
            return new CommonServiceClient(BINDING, new EndpointAddress(endpoint));//构建WCF客户端实例.
发布了366 篇原创文章 · 获赞 3 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_18932003/article/details/104225859
今日推荐