我的servicestack缓存服务在响应中包含额外的斜杠

时间:2012-11-01 12:17:06

标签: c#-4.0 redis servicestack

我使用ServiceStack创建了一个缓存的Web服务。

public class ContentSearchService : ServiceBase<ContentSearch>
{
    public ICacheClient CacheClient { get; set; }

    protected override object Run(ContentSearch request)
    {


        var cacheKey = "unique_key_for_this_request2";
        return base.RequestContext.ToOptimizedResultUsingCache(this.CacheClient, cacheKey, () =>
        {
            //Delegate is executed if item doesn't exist in cache


            //Any response DTO returned here will be cached automatically
            return new ContentSearchResponse()
            {
                Contents = new List<ContentData>()
                {
                    new ContentData()
                    {
                         FileName = "testfile.jpg"
                    }
                }
            };
        });
    }
}

然后使用:

运行
IRestClient client = new JsonServiceClient("http://internal");

ContentSearch search = new ContentSearch();

ContentSearchResponse response = client.Put<ContentSearchResponse>("/json/syncreply/ContentSearch", search);

第一个响应按预期返回并转换为响应对象。第二个是缓存的,带有额外的斜杠,因此无法序列化。

第一反应:

{"Contents":[{"FileName":"testfile.jpg","Company":0,"Version":0}]}

第二回应:

{\"Contents\":[{\"FileName\":\"testfile.jpg\",\"Company\":0,\"Version\":0}]}

我正在使用Redis作为缓存。

我已经看过他们用斜杠存储的redis服务器。

1 个答案:

答案 0 :(得分:1)

事实证明这与使用不同版本的ServiceStack程序集的客户端有关。我将服务器和客户端更新为最新的,一切都按预期工作。