/*******************************************************************************
* Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
* 类的信息:
* 1.程序名称:ServicesBase.cs
* 2.功能描述:服务基类,取得服务访问验证信息。
* 编辑履历:
* 作者 日期 版本 修改内容
* 陈晓野 2014/09/16 1.00 新建
*******************************************************************************/
using System;
using System.ServiceModel;
using Curtain.Log;
using Dongke.IBOSS.PRD.Basics.BaseResources;
using Dongke.IBOSS.PRD.Basics.Library;
using Dongke.IBOSS.PRD.Service.DataModels;
using Dongke.IBOSS.PRD.Service.DKIBOSSPRDLogic;
using Dongke.IBOSS.PRD.WCF.DataModels;
namespace Dongke.IBOSS.PRD.WCF.Services
{
///
/// 服务基类
///
public class ServicesBase
{
#region 属性
///
/// 服务访问用户信息
///
public SUserInfo SUserInfo
{
get;
private set;
}
#endregion
#region 构造函数
///
/// 构造函数
///
public ServicesBase()
{
OperationContext opc = OperationContext.Current;
if (opc == null)
{
return;
}
string action = opc.IncomingMessageHeaders.Action;
if (action == null)
{
throw new Exception("Action is null");
}
action = action.Substring(action.LastIndexOf("/") + 1);
if ("DoLogin".Equals(action)
|| "IsNeedUpgrade".Equals(action)
|| "GetUpgradeInfo".Equals(action)
|| "DownloadUpgradeFile".Equals(action)
|| "LoadUpgradeInfo".Equals(action)
|| "DownloadSetUpFile".Equals(action)
|| "GetServiceState".Equals(action))
{
// 无需验证的方法
return;
}
try
{
LoginRequestEntity requestEntity = this.GetHeaderValue(Constant.S_WCF_MESSAGE_HEADER_NAME);
SUserInfo sUserInfo = null;
string loginStatus = DKIBOSSPRDLogic.AuthenticateRepeatLogin(requestEntity, out sUserInfo);
if ("1".Equals(loginStatus))
{
// 用户登录信息错误
throw new Exception("LoginInfoError");
}
else if ("2".Equals(loginStatus))
{
// 用户登录凭证错误
throw new Exception("RepeatLogin");
}
else if ("3".Equals(loginStatus))
{
// Lic错误
throw new Exception("LicInfoError");
}
SUserInfo = sUserInfo;
}
catch (Exception ex)
{
//OutputLog.TraceLog(LogPriority.Error,
// this.ToString(),
// System.Reflection.MethodBase.GetCurrentMethod().Name,
// ex.ToString(),
// LocalPath.LogExePath);
//throw new Exception("LoginInfoError", ex);
throw ex;
}
}
#endregion
#region 私有方法
///
/// 获取验证头信息的值
///
///
///
private T GetHeaderValue(string name)
{
int index = OperationContext.Current.IncomingMessageHeaders.FindHeader(name, Constant.S_WCF_MESSAGE_HEADER_NAMESPACE);
if (index > -1)
{
return OperationContext.Current.IncomingMessageHeaders.GetHeader(index);
}
return default(T);
}
#endregion
}
}