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. 解决play framework play控制台乱码问题

    2.0以下版本 C:\Program Files\play-1.2.3\framework\pym\play 目录下的application.py  修改245行中的java_args.append( ...

  2. eclipse中代码注释

    1.类注释 Window->Preference->Java->Code Style->Code Template alt+shift+J 默认的快捷键 或者 先敲“/”在敲两 ...

  3. android github

    Action Bars ActionBarSherlock Extended ActionBar FadingActionBar GlassActionBar v7 appcompat library ...

  4. Centos安装(更新)git(亲测有效)

    Centos 6.5默认安装的是git 1.7.X 版本,使用过程中会有一些奇怪的问题,对于用户名.密码支持不是很友好.将Centos6.5上的git更新到2.0.5,方法如下: 1.安装编译git时 ...

  5. (medium)LeetCode 210.Course Schedule II

    There are a total of n courses you have to take, labeled from 0 to n - 1. Some courses may have prer ...

  6. flexgrid的应用

    第一.导入必须的CSS与JS: <link rel="stylesheet" type="text/css" href="css/flexigr ...

  7. MFC学习 socket

    下面未处理异常 tcpserver.cpp #include "WinSock2.h" #include <stdio.h> #pragma comment(lib, ...

  8. java解析xml的4种经典方法

    ========================================== xml文件 <?xml version="1.0" encoding="GB2 ...

  9. Openstack-Mitaka Ceilometer 中使用 SNMP 监控真实物理机

    Ceilometer 是 Openstack 的监控管理计费模块,我所用的版本为 Mitaka 版本.在 Ceilometer 中,可以使用 SNMP 监控服务器的实时硬件资源信息. 系统环境为 Ce ...

  10. 华为OJ平台——密码强度等级

    题目描述: 密码按如下规则进行计分,并根据不同的得分为密码进行安全等级划分. 一.密码长度: 5 分: 小于等于4 个字符 10 分: 5 到7 字符 25 分: 大于等于8 个字符 二.字母: 0  ...