zoukankan      html  css  js  c++  java
  • 知道WCF的地址用工厂通道方式快速调用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 } 

  • 相关阅读:
    Solution SQL Server 2008 Configuration Manager Cannot open problem.
    Grant, Revoke, Deny
    Solution: 无法察看SQL Server 数据库属性 错误: &quot;There is no row at position 0. (System.Data)&quot;
    SQL SMO 学习
    恢复误删的桌面 回收站
    SQL Server Security Understanding.
    SQL Server 中的 Schema, User, Login, Role
    形而上学 辩证法
    文档归档的配置发送
    无法从服务器加载工作流操作
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/4371451.html
Copyright © 2011-2022 走看看