Servicestack client compression fails with generic lists

梦想的初衷 提交于 2019-12-23 23:18:14

问题


This question is a follow-up to ServiceStack client compression

Servicestack natively supports client gzip/deflate compression since v4.5.5

But when I use a DTO with a property that is a generic list, that will will always be null when it reaches the service. Example below is a modded Servicestack unit-test which reproduces the issue:

using System.Collections.Generic;
using System.Runtime.Serialization;

using Funq;

using NUnit.Framework;

using ServiceStack;

[TestFixture]
public class ServiceStackTest
{
    private readonly ServiceStackHost appHost;

    public ServiceStackTest()
    {
        appHost = new AppHost().Init().Start("http://localhost:8105/");
    }

    [Test]
    public void Can_send_GZip_client_request()
    {
        var client = new JsonServiceClient("http://localhost:8105/") { RequestCompressionType = CompressionTypes.GZip, };
        var hello = new Hello { Name = "GZIP", Test = new List<string> { "Test" } };

        // "Hello" has valid Test-list with one value
        var response = client.Post(hello);
        Assert.That(response.Result, Is.EqualTo("Hello, GZIP (1)"));
    }

    class AppHost : AppSelfHostBase
    {
        public AppHost()
            : base(nameof(ServiceStackTest), typeof(HelloService).GetAssembly())
        {
        }

        public override void Configure(Container container)
        {
        }
    }
}

[DataContract]
[Route("/hello")]
[Route("/hello/{Name}")]
public class Hello : IReturn<HelloResponse>
{
    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public List<string> Test { get; set; }
}

[DataContract]
public class HelloResponse
{
    [DataMember]
    public string Result { get; set; }
}

public class HelloService : IService
{
    public object Any(Hello request)
    {
        // "Hello" has null request.Test
        return new HelloResponse { Result = $"Hello, {request.Name} ({request.Test?.Count})" };
    }
}

Is there a bug or am I missing something?


回答1:


This issue should now be resolved with this commit which now works as expected:

var client = new JsonServiceClient(baseUrl)
{
    RequestCompressionType = CompressionTypes.GZip,
};
var response = client.Post(new HelloGzip
{
    Name = "GZIP",
    Test = new List<string> { "Test" }
});
response.Result //= Hello, GZIP (1)

This fix is now available from v4.5.5+ that's now available on MyGet, if you have an existing v4.5.5+ installed you'll need to clear your NuGet packages cache.



来源:https://stackoverflow.com/questions/41466387/servicestack-client-compression-fails-with-generic-lists

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!