ServiceBase.cs 4.1 KB

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