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
    {
        protected static log4net.ILog log = log4net.LogManager.GetLogger("logCommon");
        private int operId = 0;
        protected string token = "";
        /// 
        /// 字典立即生效,逻辑对象会重新实例化
        /// 
       // 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("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;
        }
       
       
    }
}