当前位置: 首页 > news >正文

南京手机网站住房城市乡建设部网站

南京手机网站,住房城市乡建设部网站,注册资金500万的公司需要多少钱,h5响应式的网站现在.NET Core貌似很火#xff0c;与其他.NET开发者交流不说上几句.NET Core都感觉自己落伍了一样。但是冷静背后我们要也看到.NET Core目前还有太多不足#xff0c;别的不多说#xff0c;与自家的服务框架WCF集成起来就不咋地#xff0c;从最初不支持#xff0c;到现在有… 现在.NET Core貌似很火与其他.NET开发者交流不说上几句.NET Core都感觉自己落伍了一样。但是冷静背后我们要也看到.NET Core目前还有太多不足别的不多说与自家的服务框架WCF集成起来就不咋地从最初不支持到现在有个笨笨咔咔的Web Service Reference Provider生成的代理类简直不堪入目还特别的慢。所以本人本着为将来框架的兼容性做准备就着手研究了下能不能不通过代理类访问WCF好在微软开源了一部分WCF代码。WCF的开发者一定很熟悉WCF的所有配置都是可以通过代码和配置文件两种方式而大多数开发者都会选择配置文件但是从.NET Core开始微软干掉了Web/App.config不知道别人怎么样反正我是非常之不习惯。干掉Web/App.config的后果就是开源支持.NET Core的那部分Client Side没有配置文件的支持翻看源码后发现只要是读取配置文件的地方都是这样的代码 —— PlatformNotSupported。protected void InitializeEndpoint(string configurationName, EndpointAddress address){            _serviceEndpoint this.CreateDescription();            ServiceEndpoint serviceEndpointFromConfig null;            // Project N and K do not support System.Configuration, but this method is part of Windows Store contract.            // The configurationNamenull path occurs in normal use.            if (configurationName ! null)            {                throw ExceptionHelper.PlatformNotSupported();                // serviceEndpointFromConfig ConfigLoader.LookupEndpoint(configurationName, address, this.serviceEndpoint.Contract);       }}但是好在微软又推出了System.Configuration.ConfigurationManager的NuGet包所以本人仿照WCF原生的配置文件自己实现一套配置经过两个晚上的战斗已经成功。好了废话不多说上代码了。先看看最终的效果是什么样的WCF服务端的代码结构如下采用标准的WCF分层方式用控制台做宿主其中IAppService项目版本为.NET Standard 2.0每个终结点同时使用BasicHttpBinding与NetTcpBinding双重绑定配置文件如下?xml version1.0 encodingutf-8?configuration  !--WCF配置--  system.serviceModel    !--WCF服务配置手动增加service节点--    services      !--产品服务配置--      service behaviorConfigurationDefaultBehavior nameWCF.AppService.Implements.ProductService        host          baseAddresses            add baseAddresshttp://localhost:8098/Hosts/ProductService.svc /            add baseAddressnet.tcp://localhost:8099/Hosts/ProductService.svc /          /baseAddresses        /host        endpoint bindingbasicHttpBinding bindingConfigurationbasicBinding contractWCF.IAppService.Interfaces.IProductService /        endpoint bindingnetTcpBinding bindingConfigurationtcpBinding contractWCF.IAppService.Interfaces.IProductService /      /service      !--订单服务配置--      service behaviorConfigurationDefaultBehavior nameWCF.AppService.Implements.OrderService        host          baseAddresses            add baseAddresshttp://localhost:8098/Hosts/OrderService.svc /            add baseAddressnet.tcp://localhost:8099/Hosts/OrderService.svc /          /baseAddresses        /host        endpoint bindingbasicHttpBinding bindingConfigurationbasicBinding contractWCF.IAppService.Interfaces.IOrderService /        endpoint bindingnetTcpBinding bindingConfigurationtcpBinding contractWCF.IAppService.Interfaces.IOrderService /      /service      !--集成服务配置--      service behaviorConfigurationDefaultBehavior nameWCF.AppService.Implements.IntegrationService        host          baseAddresses            add baseAddresshttp://localhost:8098/Hosts/IntegrationService.svc /            add baseAddressnet.tcp://localhost:8099/Hosts/IntegrationService.svc /          /baseAddresses        /host        endpoint bindingbasicHttpBinding bindingConfigurationbasicBinding contractWCF.IAppService.Interfaces.IIntegrationService /        endpoint bindingnetTcpBinding bindingConfigurationtcpBinding contractWCF.IAppService.Interfaces.IIntegrationService /      /service    /services    !--WCF行为配置配置好无需修改--    behaviors      serviceBehaviors        behavior nameDefaultBehavior          !--是否允许get请求访问--          serviceMetadata httpGetEnabledtrue /          !--允许从请求消息头中检索元数据地址信息--          useRequestHeadersForMetadataAddress /          !--是否显示异常信息--          serviceDebug includeExceptionDetailInFaultstrue /          !--最大序列化的对象个数--          dataContractSerializer maxItemsInObjectGraph2147483647 /        /behavior      /serviceBehaviors    /behaviors    !--WCF绑定配置配置好无需修改--    bindings      netTcpBinding        binding nametcpBinding maxBufferPoolSize2147483647 maxBufferSize2147483647 maxReceivedMessageSize2147483647 closeTimeout00:10:00 openTimeout00:10:00 receiveTimeout00:10:00 sendTimeout00:10:00 /      /netTcpBinding      basicHttpBinding        binding namebasicBinding maxBufferPoolSize2147483647 maxBufferSize2147483647 maxReceivedMessageSize2147483647 closeTimeout00:10:00 openTimeout00:10:00 receiveTimeout00:10:00 sendTimeout00:10:00 /      /basicHttpBinding    /bindings    !--WCF多宿主绑定配置--    serviceHostingEnvironment multipleSiteBindingsEnabledtrue /  /system.serviceModel/configuration运行测试没问题服务端不多说重点是客户端因为IAppService是.NET Standard 2.0的类库版本所以.NET Core客户端是可以正常引用的新建.NET Core控制台并引用上述IAppService项目。客户端项目结构如下客户端配置文件如下?xml version1.0 encodingutf-8 ?configuration  configSections    !--WCF配置节点--    section namesystem.serviceModel typeSystem.ServiceModel.ServiceModelSection, System.ServiceModel.Toolkits /  /configSections  !--WCF配置--  system.serviceModel    !--WCF客户端配置手动增加endpoint节点--    client      !--商品服务契约配置--      endpoint addressnet.tcp://localhost:8099/Hosts/ProductService.svc bindingnetTcpBinding contractWCF.IAppService.Interfaces.IProductService nameWCF.IAppService.Interfaces.IProductService        headerProvider typeWCF.Core.Client.HeaderProviders.MyHeaderProvider assemblyWCF.Core.Client/      /endpoint      !--订单服务契约配置--      endpoint addressnet.tcp://localhost:8099/Hosts/OrderService.svc bindingnetTcpBinding contractWCF.IAppService.Interfaces.IOrderService nameWCF.IAppService.Interfaces.IOrderService /      !--集成服务契约配置--      endpoint addressnet.tcp://localhost:8099/Hosts/IntegrationService.svc bindingnetTcpBinding contractWCF.IAppService.Interfaces.IIntegrationService nameWCF.IAppService.Interfaces.IIntegrationService /    /client  /system.serviceModel/configurationMain方法中代码如下class Program    {        static void Main(string[] args)        {            //初始化容器            IContainer container InitContainer();            //调用            IProductService productService container.ResolveIProductService();            string products productService.GetProducts();            Console.WriteLine(products);            container.Dispose();            Console.ReadKey();        }        static IContainer InitContainer()        {            ContainerBuilder builder new ContainerBuilder();            Assembly wcfInterfaceAssembly Assembly.Load(WCF.IAppService);            //获取WCF接口类型集            IEnumerableType types wcfInterfaceAssembly.GetTypes().Where(type type.IsInterface);            //获取服务代理泛型类型            Type proxyGenericType typeof(ServiceProxy);            //注册WCF接口            foreach (Type type in types)            {                Type proxyType proxyGenericType.MakeGenericType(type);                PropertyInfo propChannel proxyType.GetProperty(ServiceProxy.ChannelPropertyName, type);                builder.RegisterType(proxyType).OnRelease(proxy ((IDisposable)proxy).Dispose());                builder.Register(container propChannel.GetValue(container.Resolve(proxyType))).                    As(type).                    OnRelease(channel channel.CloseChannel());            }            return builder.Build();        }    }启动运行结果如下怎么样是不是觉得很清爽如果你有兴趣可以到我的Git看全部源码地址如下https://gitee.com/lishilei0523/WCF-DotNetCorePs因为微软公开的WCF类库本身就不完善所以我也没法提供全部的功能本人所作调用方式目前支持BasicHttpBinding和NetTcpBinding并且包含消息头支持。如果你觉得代码对你有帮助麻烦点个Star不胜感激。欢迎进入我的码云 https://gitee.com/lishilei0523原文地址:http://www.cnblogs.com/lishilei0523/p/8886483.html.NET社区新闻深度好文欢迎访问公众号文章汇总 http://www.csharpkit.com
http://www.zqtcl.cn/news/564703/

相关文章:

  • 宁波拾谷网站建设蚌埠网站建设中心
  • 青岛专业设计网站公司加拿大广播公司
  • 盘锦市建设局网站地址八桂职教网技能大赛
  • 投资建设一个网站多少钱和淘宝同时做电商的网站
  • 做动物网站的素材icp备案 网站备案
  • 找人建网站唐山网络运营推广
  • 福建省住房建设厅网站6网站简历模板
  • 医疗网站模版杭州工商注册
  • 正保建设工程网站logo创意
  • 简洁个人博客网站模板下载用自己电脑做网站服务器-phpstudy+花生壳
  • 网页模板下载哪个网站好多个域名指定同一个网站好处
  • 北京网站建设有哪些公司微网站的案例
  • 常德经开区网站官网域名备案关闭网站吗
  • 做宠物网站的工作室做网站租服务器
  • 2017做那个网站致富网站换源码如何保留以前的文章
  • php网站开发实例教程书wordpress博客页面显示文章在哪
  • 地方o2o同城网站源码微信app开发价格表
  • 花木公司网站源码双语外贸网站源码
  • 什么公司做网站会提供源代码创业做招商加盟类网站赚钱
  • 东莞网站建设排名基因数据库网站开发价格
  • 天河区营销型网站建设科技自立自强
  • 网站域名账号江苏百度推广代理商
  • 专题网站建站对网站分析
  • 外贸出口网站建设如何搭建自己的网站服务器
  • 云南省建设厅网站职称评审房地产推广方案和推广思路
  • 湘潭建设路街道网站app的设计与开发
  • 《网站开发实践》 实训报告广告策划书案例完整版
  • 一级 爰做片免费网站做中学学中做网站
  • 网站排名如何提升网络营销的有哪些特点
  • 巨腾外贸网站建设个人主页网站模板免费