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

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

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

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
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地址

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/// <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的版本号

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
/// <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;
}

 

 

转载于:https://www.cnblogs.com/liulun/archive/2010/01/06/1640473.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值