• 无配置 wcf Client


    public sealed class WCFFactory<TChannel> : ChannelFactory<TChannel>
        {
            public static WCFFactory<TChannel> GetFactorty()
            {
                WSHttpBinding binding = new WSHttpBinding();
                EndpointAddress address = new EndpointAddress(new Uri(string.Format("http://{0}/Bll/",ConfigurationManager.AppSettings["hostIP"])));
                binding.MaxReceivedMessageSize = 6553600;
                binding.MaxBufferPoolSize = 52428800;
                binding.ReaderQuotas.MaxDepth = 3200;
                binding.ReaderQuotas.MaxStringContentLength = 819200;
                binding.ReaderQuotas.MaxArrayLength = 16384;
                binding.ReaderQuotas.MaxBytesPerRead = 409600;
                binding.ReaderQuotas.MaxNameTableCharCount = 16384;
    
                ContractDescription description = ContractDescription.GetContract(typeof(TChannel));
    
                ServiceEndpoint endpoint = new ServiceEndpoint(description, binding, address);
                return new WCFFactory<TChannel>(endpoint);
            }
    
            private WCFFactory(ServiceEndpoint endpoint)
                : base(endpoint)
            {
    
            }
        }
    客户端调用
    using (WCFFactory<IEngine> ChannelFactory = Factory.WCFFactory<IEngine>.GetFactorty())
                {
                    IEngine proxy = ChannelFactory.CreateChannel();
                    Console.WriteLine(proxy.GetHTMLByArticle("1"));
                    Console.ReadLine();
    
                }
    
    这样就可以不用在config文件里每次都去修改了

      

    
    

     public sealed class WCFFactory<TChannel> : ChannelFactory<TChannel>     {         public static WCFFactory<TChannel> GetFactorty()         {             WSHttpBinding binding = new

  • 相关阅读:
    frp穿透.md
    6_模板与渲染.md
    4_多数据格式返回请求结果.md
    3_请求参数绑定与多数据格式处理.md
    5_中间件.md
    1_go_gin介绍.md
    2_Gin网络请求与路由处理.md
    14_文件.md
    firefox油猴脚本编写.md
    js 四舍五入
  • 原文地址:https://www.cnblogs.com/stanley107/p/2823096.html
Copyright © 2020-2023  润新知