ServiceBase.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*******************************************************************************
  2. * Copyright(c) 2014 DongkeSoft All rights reserved. / Confidential
  3. * 类的信息:
  4. * 1.程序名称:ServicesBase.cs
  5. * 2.功能描述:服务基类,取得服务访问验证信息。
  6. * 编辑履历:
  7. * 作者 日期 版本 修改内容
  8. * 陈晓野 2014/09/16 1.00 新建
  9. *******************************************************************************/
  10. using System;
  11. using System.ServiceModel;
  12. using Dongke.IBOSS.PRD.Basics.BaseResources;
  13. using Dongke.IBOSS.PRD.Basics.Library;
  14. using Dongke.IBOSS.PRD.Service.DataModels;
  15. using Dongke.IBOSS.PRD.Service.DKIBOSSPRDLogic;
  16. using Dongke.IBOSS.PRD.WCF.DataModels;
  17. namespace Dongke.IBOSS.PRD.WCF.Services
  18. {
  19. /// <summary>
  20. /// 服务基类
  21. /// </summary>
  22. public class ServicesBase
  23. {
  24. #region 属性
  25. /// <summary>
  26. /// 服务访问用户信息
  27. /// </summary>
  28. public SUserInfo SUserInfo
  29. {
  30. get;
  31. private set;
  32. }
  33. #endregion
  34. #region 构造函数
  35. /// <summary>
  36. /// 构造函数
  37. /// </summary>
  38. public ServicesBase()
  39. {
  40. OperationContext opc = OperationContext.Current;
  41. if (opc == null)
  42. {
  43. return;
  44. }
  45. string action = opc.IncomingMessageHeaders.Action;
  46. if (action == null)
  47. {
  48. throw new Exception("Action is null");
  49. }
  50. action = action.Substring(action.LastIndexOf("/") + 1);
  51. if ("DoLogin".Equals(action)
  52. || "IsNeedUpgrade".Equals(action)
  53. || "GetUpgradeInfo".Equals(action)
  54. || "DownloadUpgradeFile".Equals(action)
  55. || "LoadUpgradeInfo".Equals(action)
  56. || "DownloadSetUpFile".Equals(action)
  57. || "GetServiceState".Equals(action))
  58. {
  59. // 无需验证的方法
  60. return;
  61. }
  62. try
  63. {
  64. LoginRequestEntity requestEntity = this.GetHeaderValue<LoginRequestEntity>(Constant.S_WCF_MESSAGE_HEADER_NAME);
  65. SUserInfo sUserInfo = null;
  66. string loginStatus = DKIBOSSPRDLogic.AuthenticateRepeatLogin(requestEntity, out sUserInfo);
  67. if ("1".Equals(loginStatus))
  68. {
  69. // 用户登录信息错误
  70. throw new Exception("LoginInfoError");
  71. }
  72. else if ("2".Equals(loginStatus))
  73. {
  74. // 用户登录凭证错误
  75. throw new Exception("RepeatLogin");
  76. }
  77. else if ("3".Equals(loginStatus))
  78. {
  79. // Lic错误
  80. throw new Exception("LicInfoError");
  81. }
  82. SUserInfo = sUserInfo;
  83. }
  84. catch (Exception ex)
  85. {
  86. //OutputLog.TraceLog(LogPriority.Error,
  87. // this.ToString(),
  88. // System.Reflection.MethodBase.GetCurrentMethod().Name,
  89. // ex.ToString(),
  90. // LocalPath.LogExePath);
  91. //throw new Exception("LoginInfoError", ex);
  92. throw ex;
  93. }
  94. }
  95. #endregion
  96. #region 私有方法
  97. /// <summary>
  98. /// 获取验证头信息的值
  99. /// </summary>
  100. /// <param name="pName"></param>
  101. /// <returns></returns>
  102. private T GetHeaderValue<T>(string name)
  103. {
  104. int index = OperationContext.Current.IncomingMessageHeaders.FindHeader(name, Constant.S_WCF_MESSAGE_HEADER_NAMESPACE);
  105. if (index > -1)
  106. {
  107. return OperationContext.Current.IncomingMessageHeaders.GetHeader<T>(index);
  108. }
  109. return default(T);
  110. }
  111. #endregion
  112. }
  113. }