知道WCF的地址用工厂通道方式快速调用WCF
2012-06-27 14:03
239 查看
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 {
public static T CreateService(Binding bind, EndpointAddress address)
{
ChannelFactory<T> channelFactory = new ChannelFactory<T>(bind);
return channelFactory.CreateChannel(address);
}
public static T CreateService(string uri)
{
#region TCP/IP方案
// NetTcpBinding bind = new NetTcpBinding();
// EndpointAddress address = new EndpointAddress("net.tcp://127.0.0.1:1785/Service");
// EndpointAddress metaAddress = new EndpointAddress("net.tcp://127.0.0.1:1785/Service/MEX");
#endregion
BasicHttpBinding bind = new BasicHttpBinding();
bind.MaxBufferSize = int.MaxValue;
bind.MaxReceivedMessageSize = int.MaxValue;
bind.MaxBufferPoolSize = int.MaxValue;
bind.ReaderQuotas.MaxArrayLength = int.MaxValue;
bind.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
bind.ReaderQuotas.MaxDepth = int.MaxValue;
bind.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
bind.ReaderQuotas.MaxStringContentLength = int.MaxValue;
bind.SendTimeout = new TimeSpan(0,5,60);
EndpointAddress address = new EndpointAddress(uri);
ChannelFactory<T> channelFactory = new ChannelFactory<T>(bind);
return CreateService(bind, address);
}
/// <summary>
/// 采用通道工厂的方式生成客户端服务对象实例
/// </summary>
/// <param name="bind"></param>
/// <param name="address"></param>
public ZhiYuan.ServiceContract.Member.ILoginService CreateLoginService()
{
return WCFClient<ZhiYuan.ServiceContract.Member.ILoginService>.CreateService("http://localhost:1785/Member/LoginService.svc");
}
public ZhiYuan.ServiceContract.Member.IMemberService CreateMemberService()
{
return WCFClient<ZhiYuan.ServiceContract.Member.IMemberService>.CreateService("http://localhost:1785/Member/MemberService.svc");
}
}63 }
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 {
public static T CreateService(Binding bind, EndpointAddress address)
{
ChannelFactory<T> channelFactory = new ChannelFactory<T>(bind);
return channelFactory.CreateChannel(address);
}
public static T CreateService(string uri)
{
#region TCP/IP方案
// NetTcpBinding bind = new NetTcpBinding();
// EndpointAddress address = new EndpointAddress("net.tcp://127.0.0.1:1785/Service");
// EndpointAddress metaAddress = new EndpointAddress("net.tcp://127.0.0.1:1785/Service/MEX");
#endregion
BasicHttpBinding bind = new BasicHttpBinding();
bind.MaxBufferSize = int.MaxValue;
bind.MaxReceivedMessageSize = int.MaxValue;
bind.MaxBufferPoolSize = int.MaxValue;
bind.ReaderQuotas.MaxArrayLength = int.MaxValue;
bind.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
bind.ReaderQuotas.MaxDepth = int.MaxValue;
bind.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;
bind.ReaderQuotas.MaxStringContentLength = int.MaxValue;
bind.SendTimeout = new TimeSpan(0,5,60);
EndpointAddress address = new EndpointAddress(uri);
ChannelFactory<T> channelFactory = new ChannelFactory<T>(bind);
return CreateService(bind, address);
}
/// <summary>
/// 采用通道工厂的方式生成客户端服务对象实例
/// </summary>
/// <param name="bind"></param>
/// <param name="address"></param>
public ZhiYuan.ServiceContract.Member.ILoginService CreateLoginService()
{
return WCFClient<ZhiYuan.ServiceContract.Member.ILoginService>.CreateService("http://localhost:1785/Member/LoginService.svc");
}
public ZhiYuan.ServiceContract.Member.IMemberService CreateMemberService()
{
return WCFClient<ZhiYuan.ServiceContract.Member.IMemberService>.CreateService("http://localhost:1785/Member/MemberService.svc");
}
}63 }
相关文章推荐
- 知道WCF的地址用工厂通道方式快速调用WCF
- C#动态调用WCF接口,两种方式任你选。
- 动态调用WCF地址 (使用ChannelFactory类)
- Post方式调用wcf服务
- 以WCF安全认证方式调用通用权限管理系统获取基础信息资料
- 客户端动态调用wcf引用地址
- WCF方式调用asmx设置cookie
- 使用WebService的方式调用部署在服务器的Wcf服务
- WCF技术剖析之二十九:换种不同的方式调用WCF服务[提供源代码下载]
- WCF客户端调用的几种方式
- 记录:Web无引用无配置方式动态调用WCF服务
- BizTalk Orchestration Publish Host In-Process Wcf Service without IIS 多种供客户端调用方式
- WCF平台下MSMQ调用方式总结
- C语言函数调用三种方式:传值调用,引用调用和传地址调用
- WCF使用地址去调用服务端的方法
- BizTalk Orchestration Publish Host In-Process Wcf Service without IIS 多种供客户端调用方式
- 7.7.3: Bean实例的创建方式及依赖配置---调用实例工厂方法创建Bean
- WCF的Restful和TCP方式调用性能比较
- WCF实现http访问地址后面带参数访问方式
- 【转】java通用URL接口地址调用方式GET和POST方式