ldj/WcfService1/basicService.cs

73 lines
1.9 KiB
C#
Raw Permalink Normal View History

2023-05-23 16:13:17 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ServiceModel;
using WcfServiceAuthentication;
using DeiNiu.Utils;
using System.Net;
namespace DeiNiu.Wcf
{
public class basicService
{
2023-09-04 22:41:19 +08:00
protected static log4net.ILog log = log4net.LogManager.GetLogger("logCommon");
2023-05-23 16:13:17 +08:00
private int operId = 0;
protected string token = "";
/// <summary>
/// 字典立即生效,逻辑对象会重新实例化
/// </summary>
// protected static bool isDicReset = false;
protected int getOperId()
{
/*
if (operId > 0) //wince set auth in the each function
{
return operId;
}
*/
try
{
// LogHelper.debug(this.GetType(), " Service class initialized., operId was " + operId);
operId = OperationContext.Current.IncomingMessageHeaders.GetHeader<int>("UserId", "www.deinu.com");//wince won't have custom heads
// LogHelper.debug(this.GetType(), " Service class initialized., operId is " + operId);
return operId;
}
catch
{
}
try
{
WebHeaderCollection headerCollection = System.ServiceModel.Web.WebOperationContext.Current.IncomingRequest.Headers;
foreach (string item in headerCollection)
{
if (item == "UserId")
{
operId = Convert.ToInt32(headerCollection.Get(item));
break;
}
}
}
catch
{
}
return operId;
}
}
}