WCF帮助类
using BJSW.ZTFX.Client.Silverlight.MapBusinessService;
using System.ServiceModel;
using System.SL.Application;
using System.Windows; namespace BJSW.ZTFX.Client.Silverlight.Common
{
public class WCFHandler : WCFHelper
{
public static string WCF_URL = "http://localHost:8012/"; /// <summary>
/// 地图业务数据(预警信息,雨情信息,河道水情,水库水情)
/// </summary>
/// <returns></returns>
public static MapBusinessDataClient GetMapBusinessDataClient()
{
if (Application.Current.IsRunningOutOfBrowser)
return new MapBusinessDataClient(GetBindHttp("BasicHttpBinding_MapBusinessData"), new EndpointAddress(WCF_URL + "MapBusinessData.svc"));
else
return new MapBusinessDataClient(GetBindHttp("BasicHttpBinding_MapBusinessData"), new EndpointAddress(WCF_URL + "MapBusinessData.svc")); }
}
}
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Text; namespace System.SL.Application
{
/// <summary>
/// 生成WCF的代理客户端
/// @create date:2010/4/25
/// </summary>
public abstract class WCFHelper
{
public static string URL;
protected static BasicHttpBinding _BindHttp;
protected static CustomBinding _BindCustom;
static WCFHelper()
{
_BindHttp = new BasicHttpBinding()
{
MaxReceivedMessageSize = ,
MaxBufferSize = ,
CloseTimeout = TimeSpan.FromMinutes(),
OpenTimeout = TimeSpan.FromMinutes(),
ReceiveTimeout = TimeSpan.FromMinutes(),
SendTimeout = TimeSpan.FromMinutes(),
TextEncoding = Encoding.UTF8,
TransferMode = System.ServiceModel.TransferMode.Buffered,
Name = "temp_http"
}; var elements = new List<BindingElement>();
elements.Add(new BinaryMessageEncodingBindingElement());
elements.Add(new HttpTransportBindingElement() { MaxReceivedMessageSize = , MaxBufferSize = });
_BindCustom= new CustomBinding(elements)
{
ReceiveTimeout = TimeSpan.FromMinutes(),
SendTimeout = TimeSpan.FromMinutes(),
OpenTimeout = TimeSpan.FromMinutes(),
CloseTimeout = TimeSpan.FromMinutes(),
Name = "temp_custom"
};
} #region 生成客户端Bind
protected static BasicHttpBinding GetBindHttp()
{
return _BindHttp;
}
protected static BasicHttpBinding GetBindHttp(string bindingName)
{
_BindHttp.Name = bindingName;
return _BindHttp;
} protected static CustomBinding GetBindCustom()
{
return _BindCustom;
}
protected static CustomBinding GetBindCustom(string bindingName)
{
_BindCustom.Name = bindingName;
return _BindCustom;
}
#endregion #region 生成WCF客户端代理
public static T GetWCFClient<T>() where T : new()
{
return new T();
}
#endregion
}
}
也可以不用设置地址
using EasySL.UI.MapAlyRef;
using EasySL.UI.MapBusinessService;
using System.ServiceModel;
using System.SL.Application;
using System.SL.Map;
using System.Windows; namespace EasySL.UI.Common
{
public class WCFHandler : WCFHelper
{
public static string WCF_URL = "http://localhost/EasySL.Web/WCF/"; /// <summary>
/// 地图业务数据(预警信息,雨情信息,河道水情,水库水情)
/// </summary>
/// <returns></returns>
public static MapBusinessDataClient GetMapBusinessDataClient()
{
if (Application.Current.IsRunningOutOfBrowser)
return new MapBusinessDataClient(GetBindHttp("BasicHttpBinding_MapBusinessData"), new EndpointAddress("../WCF/MapBusinessData.svc"));
else
return new MapBusinessDataClient(GetBindHttp("BasicHttpBinding_MapBusinessData"), new EndpointAddress("../WCF/MapBusinessData.svc")); } /// <summary>
/// 等值分析
/// </summary>
/// <returns></returns>
public static MapAlyClient GetMapAlyClient()
{
return new MapAlyClient(GetBindHttp("BasicHttpBinding_MapBusinessData"), new EndpointAddress(MapCfgHelper.BaseMapInfo.MapAnalysisUrl));
}
}
}
调用
var client = WCFHandler.GetMapBusinessDataClient();
//MapBusinessDataClient client = new MapBusinessDataClient();
client.OpenAsync();
client.QueryZQaccpCompleted += (s, e) =>
{
try
{
if (e.Error == null && e.Result != null)
{
if (e.Result.Count == )
{
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
};
client.QueryZQaccpAsync(View.BTime, View.ETime, View.type);
client.CloseAsync();
WCF帮助类的更多相关文章
- 生产WCF客户端类文件的命令格式
生产WCF客户端类文件的命令格式: svcutil.exe net.tcp://127.0.0.1:8732/ChromaMI.Remote.ConfigService/RemoteConfigSer ...
- WCF服务类的实例模式(本文为转载)
WCF开发时如何选择正确的实例模式(InstanceMode)? 在使用WCF实例模型时,你是否思考过这几个的问题: ”WCF中的实例模式如何正确应用”? ”使用WCF中的实例模式有何原则可以遵循 ...
- 终于解决:升级至.NET 4.6.1后VS2015生成WCF客户端代理类的问题
在Visual Studio 2015中将一个包含WCF引用的项目的targetFramework从4.5改为4.6.1的时候,VS2015会重新生成WCF客户端代理类.如果WCF引用配置中选中了&q ...
- WCF学习之旅—WCF寄宿前的准备(八)
一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类协定的定 ...
- (转)WCF开发框架形成之旅---WCF的几种寄宿方式
WCF寄宿方式是一种非常灵活的操作,可以在IIS服务.Windows服务.Winform程序.控制台程序中进行寄宿,从而实现WCF服务的运行,为调用者方便.高效提供服务调用.本文分别对这几种方式进行详 ...
- 系统上线后WCF服务最近经常死掉的原因分析总结
前言 最近系统上线完修改完各种bug之后,功能上还算是比较稳定,由于最近用户数的增加,不知为何经常出现无法登录.页面出现错误等异常,后来发现是由于WCF服务时不时的就死掉了.后来就开始分析问题.得到的 ...
- WCF入门教程三[WCF的宿主]
一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类契约的定 ...
- 从开发的角度比较 ASP.NET Web 服务与 WCF
Windows Communication Foundation (WCF) 具有一个 ASP.NET 兼容模式选项,用户使用此选项可以对 WCF 应用程序进行编程和配置,使其像 ASP.NET We ...
- WCF分布式开发步步为赢(8):使用数据集(DataSet)、数据表(DataTable)、集合(Collection)传递数据
数据集(DataSet).数据表(DataTable).集合(Collection)概念是.NET FrameWork里提供数据类型,在应用程序编程过程中会经常使用其来作为数据的载体,属于ADO.NE ...
随机推荐
- [AIR] 利用SnapShot.exe实现QQ截屏功能
主类(可作文档类): package { import flash.display.Bitmap; import flash.display.Sprite; import flash.events.E ...
- [Flex] ButtonBar系列——控制ButtonBar菜单是否可用
<?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...
- 怎么在logcat中显示system.com.print中的打印信息
在logcat中显示信息可以用Log.v() Log.d() Log.i() Log.w() 以及 Log.e() 1.Log.v 的调试颜色为黑色的,任何消息都会输出: 2.Log.d的输出颜色是蓝 ...
- 字典查找、linq、foreach、yield等几种查找性能对比
先上代码,以1千万记录的内存查找测试: List<Student> stuList = new List<Student>(); Dictionary<int, Stud ...
- Visual Studio 2015正式版/产品密钥 Win10正式版官方原版ISO镜像下载大全&安装激活教程
Visual Studio 2015 发行说明: https://visualstudio.com/zh-cn/news/vs2015-vs.aspx Visual Studio 2015 特性简 ...
- SQL Server中易混淆的数据类型
1)char.varchar.text和nchar.nvarchar.ntextchar和varchar的长度都在1到8000之间,它们的区别在于char是定长字符数据,而varchar是变长字符数据 ...
- poj 1094 Sorting It All Out(nyoj 349)
点击打开链接 Sorting It All Out Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24544 Accep ...
- hdu-Danganronpa(AC自动机)
Problem Description Danganronpa is a video game franchise created and developed by Spike Chunsoft, t ...
- js定时器、高亮修改单元格背景色
window.setInterval() 功能:按照指定的周期(以毫秒计)来调用函数或计算表达式. 语法:setInterval(code,millisec) 解释:code:在定时时间到时要执行的J ...
- Oracle数据库——函数 http://www.jb51.net/article/40469.htm
1====分析函数 相当于把分组后的结果加到每一行里 SELECT t.loan_contract_no,t.loan_name,t.loan_amount,ROWNUM, row_number ...