前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >WCF随客户端软件一起发布,客户端自动识别WCF服务地址,不通过配置文件绑定WCF服务,客户端动态获取版本号

WCF随客户端软件一起发布,客户端自动识别WCF服务地址,不通过配置文件绑定WCF服务,客户端动态获取版本号

作者头像
liulun
发布2022-05-09 11:22:56
5500
发布2022-05-09 11:22:56
举报
文章被收录于专栏:liulunliulun

WCF发布到IIS,并有相应的SVC宿主文件 客户端软件通过CLICK ONCE发布到WCF的相同目录下 本例实现了:客户端自动发现WCF服务的功能 1 不通过配置文件绑定WCF服务

代码语言:javascript
复制
ICallCenter proxy = null;                
BasicHttpBinding binding = new BasicHttpBinding();EndpointAddress address = new EndpointAddress(AppDeploymentUtils.GetWcfUri());
binding.MaxReceivedMessageSize = 6553600;
binding.MaxBufferPoolSize = 52428800;
binding.MaxBufferSize = 6553600;
binding.ReaderQuotas.MaxDepth = 3200;
binding.ReaderQuotas.MaxStringContentLength = 819200;
binding.ReaderQuotas.MaxArrayLength = 16384;
binding.ReaderQuotas.MaxBytesPerRead = 409600;
binding.ReaderQuotas.MaxNameTableCharCount = 16384;
ChannelFactory channelFactory = new ChannelFactory(binding, address);
proxy = channelFactory.CreateChannel();

上述代码中AppDeploymentUtils.GetWcfUri()是获取WCF地址的方法 代码详细如下 2 动态获取WCF地址

代码语言:javascript
复制
        /// <summary>
        /// 获取WCF的服务路径
        /// </summary>
        /// <returns></returns>
        public static string GetWcfUri()
        {
            if (ApplicationDeployment.IsNetworkDeployed)//是否已连接
            {
                string url = ApplicationDeployment.CurrentDeployment.UpdateLocation.AbsoluteUri.Replace("Life365.CallCenter.application", "CallCenterWCF.svc");
                return url;
            }
            else
            {
                return "http://localhost:8080/CallCenterWCF.svc";
            }
        }

3动态获取ClickOnce的版本号

代码语言:javascript
复制
        /// <summary>
        /// 获取客户端发布版本号
        /// </summary>
        /// <returns>当前版本号</returns>
        public static string GetVersiion()
        {            
            if (ApplicationDeployment.IsNetworkDeployed)//是否已连接 
            {                
                ApplicationDeployment currDeployment = ApplicationDeployment.CurrentDeployment;
                string version = currDeployment.CurrentVersion.Major.ToString();//主版本
                version += "."+currDeployment.CurrentVersion.Minor.ToString(); //次版本 
                version += "." + currDeployment.CurrentVersion.Build.ToString();//内部版本号    
                version += "." + currDeployment.CurrentVersion.Revision.ToString();//修订号             
                return version;
            }
            return string.Empty;
        }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2010-01-06,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档