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 }

最新文章

  1. node-sass报错解决方法
  2. ASP.NET SignalR入门
  3. 【Python基础学习六】函数
  4. Hello,Akka
  5. Jquery中常见问题
  6. [LeetCode]题解(python):153-Find Minimum in Rotated Sorted Array
  7. android学习ProgressBar的简单使用
  8. servlet实现mysql数据库分页
  9. sqlserver等软件下载
  10. Http&amp;Tomcat
  11. swift能干什么,不能干什么及相关概念
  12. KMS11激活Window系列
  13. @OneToMany、@ManyToOne以及@ManyToMany讲解
  14. ibatIs中的isNotNull、isEqual、isEmpty
  15. eComStation 1.2
  16. jQuery使用blur()方法触发两次的解决方法
  17. struts2标签库详解
  18. python 输入 与如何查看文档 小结
  19. Sharepoint2013商务智能学习笔记之使用Current User Filter筛选Excel 数据(六)
  20. 【Reverse Linked List II】cpp

热门文章

  1. Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes
  2. sed删除空行和开头的空格和tab键
  3. iOS边练边学--tableView的批量操作
  4. C# 字典 Dictionary 遍历
  5. 使用什么工具连接MySQL Server
  6. labview事件结构学习
  7. par函数cex参数-控制文字和点的大小
  8. 【Java 线程的深入研究3】最简单实例说明wait、notify、notifyAll的使用方法
  9. UVA - 11920 0 s, 1 s and ? Marks
  10. LoadRunner 调用dll方法