Servicestack客户端压缩失败,带有通用列表

时间:2017-01-04 14:35:46

标签: servicestack

这个问题是后续问题 ServiceStack client compression

自v4.5.5起,Servicestack本身支持客户端gzip / deflate压缩

但是当我使用具有通用列表属性的DTO时,当它到达服务时将始终为null。下面的示例是一个修改的Servicestack单元测试,它可以重现问题:

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})" };
    }
}

是否有错误或我遗失了什么?

1 个答案:

答案 0 :(得分:2)

现在应该使用this commit解决此问题,现在可以按预期工作:

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)

此修补程序现在可从v4.5.5 +现在available on MyGet获得,如果您安装了现有的v4.5.5 +,则需要clear your NuGet packages cache

相关问题