/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:OperationInvoker.cs
* 2.功能描述:服务操作者
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2014/08/13 1.00 新建
*******************************************************************************/
using System;
using System.ServiceModel;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.Library;
namespace Dongke.IBOSS.PRD.WCF.Proxys.ServiceProxy
{
///
/// 服务操作者
///
public class OperationInvoker
{
///
/// 执行
///
///
///
///
public static void Invoke(Action serviceInvocation, TChannel channel)
{
ICommunicationObject communicationObject = (ICommunicationObject)channel;
try
{
serviceInvocation(channel);
communicationObject.Close();
}
catch (Exception ex)
{
HandleException(ex, communicationObject);
}
}
///
/// 执行
///
///
///
///
///
///
public static TResult Invoke(Func serviceInvocation, TChannel channel)
{
ICommunicationObject communicationObject = (ICommunicationObject)channel;
TResult result = default(TResult);
try
{
result = serviceInvocation(channel);
communicationObject.Close();
}
catch (Exception ex)
{
HandleException(ex, communicationObject);
}
return result;
}
///
/// 异常处理
///
///
///
public static void HandleException(Exception ex, ICommunicationObject channel)
{
channel.Abort();
/*
// 通信错误 诸如网络错误,地址错误,服务器没有启动等等
// 状态异常 代理已经关闭,或者通道Fault,等问题
// 服务异常 服务调用时抛出的异常,这个服务内部异常会序列化传递给客户端,被客户端捕获
if (ex is CommunicationException)
{
// 通信错误,诸如网络错误,地址错误,服务器没有启动,验证没有通过等等
}
else if (ex is TimeoutException)
{
// 通信错误,超时
}
//else if (ex is FaultException)
//{
// // includeExceptionDetailInFaults="true"
// //FaultException ded = (ex as FaultException);
// // 服务端 应用异常
//}
else if (ex is FaultException)
{
// 服务端 应用异常
}
else if (ex is Exception)
{
}
*/
throw ex;
}
}
}