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帮助类的更多相关文章

  1. 生产WCF客户端类文件的命令格式

    生产WCF客户端类文件的命令格式: svcutil.exe net.tcp://127.0.0.1:8732/ChromaMI.Remote.ConfigService/RemoteConfigSer ...

  2. WCF服务类的实例模式(本文为转载)

    WCF开发时如何选择正确的实例模式(InstanceMode)?   在使用WCF实例模型时,你是否思考过这几个的问题: ”WCF中的实例模式如何正确应用”? ”使用WCF中的实例模式有何原则可以遵循 ...

  3. 终于解决:升级至.NET 4.6.1后VS2015生成WCF客户端代理类的问题

    在Visual Studio 2015中将一个包含WCF引用的项目的targetFramework从4.5改为4.6.1的时候,VS2015会重新生成WCF客户端代理类.如果WCF引用配置中选中了&q ...

  4. WCF学习之旅—WCF寄宿前的准备(八)

    一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类协定的定 ...

  5. (转)WCF开发框架形成之旅---WCF的几种寄宿方式

    WCF寄宿方式是一种非常灵活的操作,可以在IIS服务.Windows服务.Winform程序.控制台程序中进行寄宿,从而实现WCF服务的运行,为调用者方便.高效提供服务调用.本文分别对这几种方式进行详 ...

  6. 系统上线后WCF服务最近经常死掉的原因分析总结

    前言 最近系统上线完修改完各种bug之后,功能上还算是比较稳定,由于最近用户数的增加,不知为何经常出现无法登录.页面出现错误等异常,后来发现是由于WCF服务时不时的就死掉了.后来就开始分析问题.得到的 ...

  7. WCF入门教程三[WCF的宿主]

    一.WCF服务应用程序与WCF服务库 我们在平时开发的过程中常用的项目类型有“WCF 服务应用程序”和“WCF服务库”. WCF服务应用程序,是一个可以执行的程序,它有独立的进程,WCF服务类契约的定 ...

  8. 从开发的角度比较 ASP.NET Web 服务与 WCF

    Windows Communication Foundation (WCF) 具有一个 ASP.NET 兼容模式选项,用户使用此选项可以对 WCF 应用程序进行编程和配置,使其像 ASP.NET We ...

  9. WCF分布式开发步步为赢(8):使用数据集(DataSet)、数据表(DataTable)、集合(Collection)传递数据

    数据集(DataSet).数据表(DataTable).集合(Collection)概念是.NET FrameWork里提供数据类型,在应用程序编程过程中会经常使用其来作为数据的载体,属于ADO.NE ...

随机推荐

  1. MapHttpRoute

    http://aspnetwebstack.codeplex.com/SourceControl/latest#src/System.Web.Http/HttpRouteCollectionExten ...

  2. The 2013 ACM-ICPC Asia Changsha Regional Contest - A

    Alice's Print Service Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice is providing print ser ...

  3. github入门

    一.先了解 相比CVS\SVN优势: - 支持离线开发,离线Repository- 强大的分支功能,适合多个独立开发者协作- 速度快 github 本地有仓库,储存着所有repository的历史: ...

  4. Windows下cwRsync搭建步骤

    文章(一) CwRsync是基于cygwin平台的rsync软件包,支持windows对windows.windows对Linux.Linux对windows高效文件同步.由于CwRsync已经集成了 ...

  5. python修改excel文件

    一.导入模块如图

  6. KVM虚拟化(一)—— 介绍与简单使用

    一.架构及介绍 KVM(Kernel-based Virtual Machine)它由 Quramnet 开发,该公司于 2008年被 Red Hat 收购: 自Linux 2.6.20后整合到内核, ...

  7. 第三方框架之SDWebImage

    1. 下载SDWebImage,导入工程.github托管地址https://github.com/rs/SDWebImage 2. 在需要的地方导入头文件#import "UIImageV ...

  8. WebApi简单使用

    一.建立一个WebApi项目 WebApi项目的文件和MVC的基本项目内容差不多,都有Models View Controller等,区别在于WebApi的控制器继承的不是Controller类,而是 ...

  9. CSS3之选择器

    总结了下CSS3新增的一些选择器. CSS3的选择器有基本选择器.属性选择器.伪类选择器几类. CSS3选择器 选择器 举例 例子描述 element1~element2 p~a 选择前面有 < ...

  10. VC与JavaScript交互(四) --- WebBrowser或CHtmlView中轻松屏蔽脚本错误(JavaScript)

    1.什么是javascript脚本错误 1.1    概述 JavaScript脚本错误包含“运行时错误”和“语法错误”. 1.2    JavaScript“语法错误” JavaScript语法错误 ...