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 } 

  • 相关阅读:
    使用 ASP.NET Core MVC 创建 Web API(五)
    使用 ASP.NET Core MVC 创建 Web API(四)
    使用 ASP.NET Core MVC 创建 Web API(三)
    使用 ASP.NET Core MVC 创建 Web API(二)
    使用 ASP.NET Core MVC 创建 Web API(一)
    学习ASP.NET Core Razor 编程系列十九——分页
    学习ASP.NET Core Razor 编程系列十八——并发解决方案
    一个屌丝程序猿的人生(九十八)
    一个屌丝程序猿的人生(九十七)
    一个屌丝程序猿的人生(九十五)
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/4371451.html
Copyright © 2011-2022 走看看