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


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

    1 不通过配置文件绑定WCF服务

    代码
    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地址

    代码
    /// <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的版本号

    代码
    /// <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;
    }
  • 相关阅读:
    pandas openpyxl 设置Excel 列宽自适应
    tar 打包当前目录下文件但不包括该录
    pandas美化excel高亮某行
    学习笔记260—NMF 非负矩阵分解的原理及应用
    学习笔记259—低秩分解
    学习笔记258—张量的背景
    学习笔记261—MATLAB 不能保存变量问题及解决办法
    Creating PDF Reports with Pandas, Jinja and WeasyPrint
    520论文
    使用bat获取win设备信息
  • 原文地址:https://www.cnblogs.com/liulun/p/1640473.html
Copyright © 2020-2023  润新知