Servicestack客户端压缩使用通用列表失败 [英] Servicestack client compression fails with generic lists
本文介绍了Servicestack客户端压缩使用通用列表失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从v4.5.5开始,Servicestack本机支持客户端GZIP/DEFATE压缩
但是,当我使用具有泛型列表属性的DTO时,当它到达服务时,它将始终为空。下面的示例是修改后的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})" };
}
}
是有错误还是我遗漏了什么?
推荐答案
现在应该使用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。
这篇关于Servicestack客户端压缩使用通用列表失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文