| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- /*******************************************************************************
- * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
- * 类的信息:
- * 1.程序名称:ServicesBase.cs
- * 2.功能描述:服务基类,取得服务访问验证信息。
- * 编辑履历:
- * 作者 日期 版本 修改内容
- * 陈晓野 2014/09/16 1.00 新建
- *******************************************************************************/
- using System;
- using System.ServiceModel;
- 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
- {
- /// <summary>
- /// 服务基类
- /// </summary>
- public class ServicesBase
- {
- #region 属性
- /// <summary>
- /// 服务访问用户信息
- /// </summary>
- public SUserInfo SUserInfo
- {
- get;
- private set;
- }
- #endregion
- #region 构造函数
- /// <summary>
- /// 构造函数
- /// </summary>
- 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<LoginRequestEntity>(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 私有方法
- /// <summary>
- /// 获取验证头信息的值
- /// </summary>
- /// <param name="pName"></param>
- /// <returns></returns>
- private T GetHeaderValue<T>(string name)
- {
- int index = OperationContext.Current.IncomingMessageHeaders.FindHeader(name, Constant.S_WCF_MESSAGE_HEADER_NAMESPACE);
- if (index > -1)
- {
- return OperationContext.Current.IncomingMessageHeaders.GetHeader<T>(index);
- }
- return default(T);
- }
- #endregion
- }
- }
|