知道WCF的地址用工厂通道方式快速调用WCF
2024-09-29 11:55:26
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 }
最新文章
- node-sass报错解决方法
- ASP.NET SignalR入门
- 【Python基础学习六】函数
- Hello,Akka
- Jquery中常见问题
- [LeetCode]题解(python):153-Find Minimum in Rotated Sorted Array
- android学习ProgressBar的简单使用
- servlet实现mysql数据库分页
- sqlserver等软件下载
- Http&;Tomcat
- swift能干什么,不能干什么及相关概念
- KMS11激活Window系列
- @OneToMany、@ManyToOne以及@ManyToMany讲解
- ibatIs中的isNotNull、isEqual、isEmpty
- eComStation 1.2
- jQuery使用blur()方法触发两次的解决方法
- struts2标签库详解
- python 输入 与如何查看文档 小结
- Sharepoint2013商务智能学习笔记之使用Current User Filter筛选Excel 数据(六)
- 【Reverse Linked List II】cpp
热门文章
- Android Studio:Multiple dex files define Landroid/support/annotation/AnimRes
- sed删除空行和开头的空格和tab键
- iOS边练边学--tableView的批量操作
- C# 字典 Dictionary 遍历
- 使用什么工具连接MySQL Server
- labview事件结构学习
- par函数cex参数-控制文字和点的大小
- 【Java 线程的深入研究3】最简单实例说明wait、notify、notifyAll的使用方法
- UVA - 11920 0 s, 1 s and ? Marks
- LoadRunner 调用dll方法