/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:OperationInvoker_T.cs
* 2.功能描述:服务操作者
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2014/08/13 1.00 新建
*******************************************************************************/
using System;
using System.ServiceModel;
using Dongke.IBOSS.PRD.Basics.Library;
namespace Dongke.IBOSS.PRD.WCF.Proxys.ServiceProxy
{
///
/// 服务操作者
///
///
public class OperationInvoker : OperationInvoker
{
///
/// 终点名
///
public string EndpointName
{
get;
private set;
}
///
/// 服务操作者
///
///
public OperationInvoker(string endpointName)
{
this.EndpointName = endpointName;
}
///
/// 执行
///
///
/// 超时(分钟)
public void Invoke(Action serviceInvocation, double timeout = 0)
{
ChannelFactory channelFactory = ChannelFactories.GetFactory(this.EndpointName);
TChannel channel = channelFactory.CreateChannel();
IContextChannel icc = channel as IContextChannel;
if (icc != null)
{
if (timeout > 0)
{
icc.OperationTimeout = TimeSpan.FromMinutes(timeout);
}
else
{
// 不能大于24天,否则异常。
icc.OperationTimeout = TimeSpan.FromDays(20);
}
}
Invoke(serviceInvocation, channel);
}
///
/// 执行
///
///
///
/// 超时(分钟)
///
public TResult Invoke(Func serviceInvocation, double timeout = 0)
{
ChannelFactory channelFactory = ChannelFactories.GetFactory(this.EndpointName);
TChannel channel = channelFactory.CreateChannel();
IContextChannel icc = channel as IContextChannel;
if (icc != null)
{
if (timeout > 0)
{
icc.OperationTimeout = TimeSpan.FromMinutes(timeout);
}
else
{
// 不能大于24天,否则异常。
icc.OperationTimeout = TimeSpan.FromDays(20);
}
}
return Invoke(serviceInvocation, channel);
}
}
}