博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
知道WCF的地址用工厂通道方式快速调用WCF
阅读量:7173 次
发布时间:2019-06-29

本文共 1990 字,大约阅读时间需要 6 分钟。

 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 } 

转载地址:http://avbzm.baihongyu.com/

你可能感兴趣的文章
服务器资源使用情况统计--脚本
查看>>
Oracle查询数据库的索引字段以及查询用索引
查看>>
第二讲、实例变量可见度、方法
查看>>
zabbix监控基础知识
查看>>
mysql四:数据操作
查看>>
Div的定位
查看>>
Activity ca.ct.activity.OBaccaratActivity has leak
查看>>
nginx+tomcat+resin+jdk一键自动化安装脚本(1--父shell安装脚本)
查看>>
strspn
查看>>
Rancher如何对接Ceph-RBD块存储
查看>>
3DTouch学习笔记
查看>>
Linux下 vi 操作Found a swap file by the name
查看>>
filebeat 插件开发
查看>>
网络基础
查看>>
技术加油站:5月19日,技术大佬等你来撩
查看>>
supervisor配置详解(转)
查看>>
Confluence 6 Microsoft SQL Server 设置准备
查看>>
Nginx.conf配置文件
查看>>
EI检索期刊JA检索与CA检索有什么区别?
查看>>
人脸识别技术探讨:1:1,1:小N/大N,大姿态识别,活体识别
查看>>