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 ...
随机推荐
- python连接hiveserver2
sudo pip install pyhs2 网上找的例子: #!/usr/bin/env python # -*- coding: utf-8 -*- # hive util with hive s ...
- OC基础(9)
OC中的私有方法 @property基本概念 @synthesize基本概念 @property增强 @property修饰符 *:first-child { margin-top: 0 !impor ...
- 前端开发 Grunt 之 Connect
在前端开发过程中,我们需要在开发过程中,将开发中的站点部署到服务器上,然后,在浏览器中查看实际的效果,在 Grunt 环境下,可以直接使用集成在 Grunt 中的 Connect 插件完成站点服务器的 ...
- jmeter随笔(3)-从csv中获取带引号的数据详情
最近在工作中,对jmeter实践的点滴的记录这里分享,不一定正确,仅供参考和讨论,有想法的欢迎留言.谈论. 1技巧1:从csv中获取带引号的数据详情 背景:我们从csv中获取数据,在jmeter中使用 ...
- Custom Date tag
Custom Date tag: custom date based on pattern format. Default date is current day. <CUSTOMDATE[+, ...
- MySQL的体系结构
因为MySQL采用的是客户机/服务器体系结构,所以你在使用MySQL存取数据时,必须至少使用两个或者说两类程序: 一个位于存放您的数据的主机上的程序 ----数据库服务器.数据库服务器监听从网络上传过 ...
- MSP430F149学习之路——捕获/比较模式
1.捕获模式 #include <msp430x14x.h> unsigned ,last1=; unsigned ,j=; void mian(void) { WDTCTL = WDTP ...
- openldap安装配置
http://www.jslink.org/linux/openldap-ssl-sssd.html http://www.unix-power.net/centos7/openldap.html h ...
- SDL2 Tutorial
Hello World for SDL2 SDL2 setting for visual studio. http://lazyfoo.net/tutorials/SDL/01_hello_SDL/w ...
- Multithreading annd Grand Central Dispatch on ios for Beginners Tutorial-多线程和GCD的入门教程
原文链接:Multithreading and Grand Central Dispatch on iOS for Beginners Tutorial Have you ever written a ...