知道WCF的地址用工厂通道方式快速调用WCF

本文介绍了使用.NET创建WCF客户端服务实例的方法,包括不同绑定配置和创建服务对象的实现。

 1
 using System;
 2 using System.ServiceModel;
 3 using System.ServiceModel.Description;
 4 using System.ServiceModel.Channels;
 5 
 6 namespace ZhiYuan.ServiceProxy
 7 {
 8     public class WCFClient<T>
 9     {
10 
11         public static T CreateService(Binding bind, EndpointAddress address)
12         {
13             ChannelFactory<T> channelFactory = new ChannelFactory<T>(bind);
14             return channelFactory.CreateChannel(address);
15         }
16         public static T CreateService(string uri)
17         {
18 
19             #region TCP/IP方案
20             // NetTcpBinding bind = new NetTcpBinding();
21             // EndpointAddress address = new EndpointAddress("net.tcp://127.0.0.1:1785/Service");
22             // EndpointAddress metaAddress = new EndpointAddress("net.tcp://127.0.0.1:1785/Service/MEX");
23             #endregion
24 
25             BasicHttpBinding bind = new BasicHttpBinding();
26             bind.MaxBufferSize = int.MaxValue;
27             bind.MaxReceivedMessageSize = int.MaxValue;
28             bind.MaxBufferPoolSize = int.MaxValue;
29             bind.ReaderQuotas.MaxArrayLength = int.MaxValue;
30             bind.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
31             bind.ReaderQuotas.MaxDepth = int.MaxValue;
32             bind.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
33             bind.ReaderQuotas.MaxStringContentLength = int.MaxValue;
34             
35            bind.SendTimeout = new TimeSpan(0,5,60);
36             EndpointAddress address = new EndpointAddress(uri);
37 
38             ChannelFactory<T> channelFactory = new ChannelFactory<T>(bind);
39             return CreateService(bind, address);
40         }
41 
42         /// <summary>
43         /// 采用通道工厂的方式生成客户端服务对象实例
44         /// </summary>
45         /// <param name="bind"></param>
46         /// <param name="address"></param>
47        public   ZhiYuan.ServiceContract.Member.ILoginService CreateLoginService()
48         {
49             return WCFClient<ZhiYuan.ServiceContract.Member.ILoginService>.CreateService("http://localhost:1785/Member/LoginService.svc");
50           
51         }
52         
53 
54        public  ZhiYuan.ServiceContract.Member.IMemberService CreateMemberService()
55        {
56           
57            return WCFClient<ZhiYuan.ServiceContract.Member.IMemberService>.CreateService("http://localhost:1785/Member/MemberService.svc");
58         
59 
60        }
61         
62     }

63 } 

转载于:https://www.cnblogs.com/caizhiyuan/archive/2012/06/27/2565730.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值