private void WriteOutputStream(SoapMessage message)
        {
            this._NewStream.Position = 0;
            this._NewStream.CopyTo(this._OldStream);
            this._NewStream.Position = 0;

            ServiceMethodConfigurationElement methodSettings = GetMethodSettings(this._RequestMessage);

            if (message.Exception == null && this._RequestMessage.UseServerCache && methodSettings.CacheEnabled)
            {
                ServiceMethodCache methodCache = this.GetMethodCacheManager().GetOrAddNewValue(this._RequestMessage.MethodCacheKey, (cache, key) =>
                {
                    T result = this.CreateServiceMethodCache(this._RequestMessage.MethodCacheKey, methodSettings.QueueLength);

                    cache.Add(key, result);

                    return(result);
                });

                using (StreamReader reader = new StreamReader(this._NewStream))
                {
                    string dataInCache = reader.ReadToEnd();

                    methodCache.Add(this._RequestMessage.Document.OuterXml, dataInCache, CreateDependency(methodSettings));
                }
            }
        }
示例#2
0
        private object InvokeWithMonitor(object instance, object[] inputs, out object[] outputs)
        {
            ServiceMethodConfigurationElement methodElement = ServiceSettings.GetConfig().GetMethodElementByOperationContext();

            object[] result = null;

            if (methodElement != null)
            {
                PerformanceMonitorHelper.DefaultMonitorName = MonitorName;
                MonitorData md = PerformanceMonitorHelper.StartMonitor(MonitorName);

                md.MonitorName     = string.Format("{0}.{1}", OperationContext.Current.GetContractName(), OperationContext.Current.GetMethodName());
                md.EnableLogging   = methodElement.EnableLogging;
                md.EnablePFCounter = methodElement.EnablePFCounter;

                md.InstanceName = md.MonitorName;
                md.Context["GlobalInstance"] = new WebMethodServerCounters("_Total_");
                md.Context["Instance"]       = new WebMethodServerCounters(md.InstanceName);

                if (md.EnableLogging)
                {
                    md.LogWriter.WriteLine("请求{0}的开始时间: {1:yyyy-MM-dd HH:mm:ss.fff}", md.MonitorName, SNTPClient.AdjustedTime);
                }

                try
                {
                    PerformanceMonitorHelper.GetDefaultMonitor().WriteExecutionDuration(md.MonitorName,
                                                                                        () =>
                    {
                        result = this.InternalInvoke(instance, inputs);
                    });
                }
                catch (System.Exception ex)
                {
                    md.HasErrors = true;

                    if (md.EnableLogging)
                    {
                        ex.WriteToEventLog(md.MonitorName, EventLogEntryType.Error, 8010);
                    }

                    throw;
                }
                finally
                {
                    CommitMonitorData();
                }
            }
            else
            {
                result = this.InternalInvoke(instance, inputs);
            }

            outputs = (object[])result[1];

            return(result[0]);
        }
        private static T GetMethodSettingAttributeValue <T>(string methodName, string attrName, T defaultValue)
        {
            T result = defaultValue;

            ServiceMethodConfigurationElement element = GetMethodSettings(methodName);

            if (element != null)
            {
                result = element.GetValue(attrName, defaultValue);
            }

            return(result);
        }
        private static ServiceMethodConfigurationElement GetMethodSettings(string methodName)
        {
            ServiceSettings settings = ServiceSettings.GetConfig();

            ServiceMethodConfigurationElement result = null;

            ServiceConfigurationElement serviceElement = settings.Services[typeof(AppSecurityCheckService).FullName];

            if (serviceElement != null)
            {
                result = serviceElement.Methods[methodName];
            }

            return(result ?? settings.MethodDefaultSettings);
        }
        private static ServiceMethodConfigurationElement GetMethodSettings(SimpleRequestSoapMessage requestMessage)
        {
            ServiceSettings settings = ServiceSettings.GetConfig();

            ServiceMethodConfigurationElement result = null;

            ServiceConfigurationElement serviceElement = settings.Services[requestMessage.ServiceName];

            if (serviceElement != null)
            {
                result = serviceElement.Methods[requestMessage.Action];
            }

            return(result ?? settings.MethodDefaultSettings);
        }
        /// <summary>
        /// 从Cache中获取数据
        /// </summary>
        /// <param name="message"></param>
        protected virtual void FetchDataFromCache(SoapMessage message)
        {
            ServiceMethodConfigurationElement methodSettings = GetMethodSettings(this._RequestMessage);

            if (this._RequestMessage.UseServerCache && methodSettings.CacheEnabled)
            {
                string dataInCache = GetDataInCache(this._RequestMessage);

                if (dataInCache != null)
                {
                    SetAfterExecuteMethodCounters(this._RequestMessage, true);

                    HttpContext.Current.Response.ContentType = "text/xml";
                    HttpContext.Current.Response.Write(dataInCache);
                    HttpContext.Current.Response.End();
                }
            }
        }
        private static DependencyBase CreateDependency(ServiceMethodConfigurationElement methodSettings)
        {
            SlidingTimeDependency slidingTimeDependency = new SlidingTimeDependency(methodSettings.CacheSlidingTime);

            return(new MixedDependency(new UdpNotifierCacheDependency(), slidingTimeDependency, new MemoryMappedFileNotifierCacheDependency()));
        }