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();