WCF缓存问题列表 [英] WCF Caching Problem List

查看:71
本文介绍了WCF缓存问题列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的极客,

我正在尝试缓存从WCF中的SQL SERVER检索到的动态列表,到目前为止,检索过程运行良好,并且我已经对其进行了测试,并且根本没有任何问题,问题是当我尝试缓存时此检索到的列表,发生错误,我无法找出其背后的原因.
这是我的方法:

Dear Geeks,

I am trying to cache a dynamic list retrieved from a SQL SERVER in WCF, the retrieving process is working fine so far, and I''ve tested it and there are no problems at all with it, the problem is when I try to cache this retrieved list, an error occurs that I am not able to find out the reason behind it.

here is my method :

public List<ErrorEntities> GetALL()
       {
           List<ErrorEntities> res = null;
           if (HttpContext.Current.Cache["GetALL"] == null)
           {
               SqlCommand com = Global.GetCommand("select * from [BlockingList]");
               com.Connection.Open();
               SqlDataReader reader = com.ExecuteReader();
               res = Fill(reader);

               HttpContext.Current.Cache.Add("GetALL", res, null, DateTime.Now.Add(new TimeSpan(0, 0, 15)), Cache.NoSlidingExpiration, CacheItemPriority.Normal, null);

               com.Connection.Close();
               return res;
           }
           else
           {
               res = HttpRuntime.Cache["GetALL"] as List<ErrorEntities>;
               return res;
           }
       }



&我尝试通过添加以下代码行来启用web.config文件上的缓存,但问题也未得到解决:



& I''ve tried to enable the caching on the web.config file by adding the following line of code but the problem wasn''t solved as well:

<scriptResourceHandler enableCompression="true"    enableCaching="true" />



这是我编译解决方案时遇到的错误:



and here is the error I get when I compile the solution:

The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

Source Error: 


Line 113:        
Line 114:        public ServiceReference1.ErrorEntities[] GetALL() {
Line 115:            return base.Channel.GetALL();
Line 116:        }
Line 117:        

推荐答案

我已经找到了解决方法

我们需要做的就是通过在web.config中添加以下行来允许aspnet缓存的兼容性:

I have figured out the solution

all we need to do here is to allow the compatibility of aspnet caching through adding the line in the web.config :

<servicehostingenvironment aspnetcompatibilityenabled="true" />   



并在您的数据访问层中,在类的顶部添加以下行,如下所示:



and in your data access layer, add the following line at the very top of your class like this :

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]



这样该类看起来像这样:



so that the class looks like this :

using System.ServiceModel.Activation;
namespace WcfService2
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]

    // NOTE: If you change the class name "Service1" here, you must also update the reference to "Service1" in Web.config and in the associated .svc file.
    public class Service1 : IService1
    {
       
        public List<errorentities> GetALL()
        {


            List<errorentities> res = null;
           if (CacheHelper.GetCache("GetALL")==null)
               {
                string cacheKey = "GetAll";
                SqlCommand com = Global.GetCommand("select * from [BlockingList]");
                com.Connection.Open();
                SqlDataReader reader = com.ExecuteReader();
                res = Fill(reader);
                CacheHelper.Cache(cacheKey, res, 2);
                com.Connection.Close();
                return res;
              
               }
           else
               {
                res = CacheHelper.GetCache("GetALL") as List<errorentities>;
                return res;
                }
        }

</errorentities></errorentities></errorentities>



如您所见,您必须添加



as you noticed you must add

using System.ModelService.Activation; 



为了使添加的服务正常工作,

希望这可以为任何人节省宝贵的时间,因为我已经为这个问题研究了3天,没有希望找到任何解决方案.



so that the added service could work,,

hope this might save for anyone his valuable time, because i''ve been working on this problem for 3days with no hope to find any solution.


这篇关于WCF缓存问题列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆