Martin A
Martin A

Reputation: 79

Servicestack client compression fails with generic lists

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?

Upvotes: 2

Views: 55

Answers (1)

mythz
mythz

Reputation: 143359

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.

Upvotes: 2

Related Questions