ServiceStack MsgPackServiceClient fails while retrieving data, but JsonServiceClient works

I play with ServiceStack and take baby steps trying to understand this technology.

I have a very simple setup (a complete solution is available for download ):

  • Standalone AppHost using ServiceStack (self)
  • I start the server
  • then I request a list of Article data.

I installed the nuget package for ServiceStack.Pluging.MsgPack and added the link and correctly installed the AppHost plugin, as shown below in the main() code.

DTO classes and services

These are the data classes, the DTO and Service classes that I use:

 public class Article : IReturn<Article> { public string AR_REF { get; set; } public string AR_DESIGN { get; set; } public string AR_CODEBARRE { get; set; } public string FA_CODEFAMILLE { get; set; } public string CT_INTITULE { get; set; } } public class Articles : IReturn<List<Article>> { } public class ArticleService : Service { public List<Article> Get(Articles request) { return new List<Article>() { new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , }; } } 

All this allows the client to get a list of 16 dummy Articles .

Server and client request

 static void Main() { var appHost = new AppHost(); appHost.Plugins.Add(new MsgPackFormat()); appHost.Init(); appHost.Start("http://localhost:8883"); // Fails when calling client.Get() var client = new MsgPackServiceClient("http://localhost:8883"); List<Article> response = client.Get(new Articles()); appHost.Stop(); } 

With AppHost it is defined as:

 public class AppHost : AppHostHttpListenerBase { static readonly ConfigurationResourceManager AppSettings = new ConfigurationResourceManager(); public AppHost() : base("Test", typeof(Article).Assembly) { } public override void Configure(Funq.Container container) { } } 

What will happen

The client.Get(...) call is not made using SerializationException :
Unpacking has not yet read the data. The decoder may never read, or the underlying stream is empty.

  • An exception occurs when I use MsgPackServiceClient() with over 15 entries.
    Oddly enough, if I return 15 or less Articles instances, it works.

  • If I use JsvServiceClient() or JsonServiceClient() instead, I have no problem returning thousands of records.

I really don’t know if I am doing something very bad or if there is something else here.

Additional Information and Download

I am using VS2012 with ServiceStack 3.9.43 (including the MsgPack plugin) installed via nuget.
The problem occurs regardless of the compilation options (AnyCPU / x86). Code optimization is not enabled (each solution / project option is standard).

You can download the full solution and try it yourself.

+4
source share
1 answer

So I'm not quite sure what the problem is. This seems to be specific to using MsgPackServiceClient in the same AppHost application. If you make the request from the browser something like http://localhost:8883/Articles?format=x-msgpack , it works.

Writing a test (e.g. from the bottom) seems to confirm the correct operation of MessagePackSerializer.

Adding an answer filter (below), which apparently writes to OutputStream, fixes your problem. I tried with 16 and 32 entries in the list.

Hope this helps.

  appHost.ResponseFilters.Add((httpReq, httpRes, dto) => { if (httpReq.ResponseContentType == ContentType.MsgPack) { using (var ms = new MemoryStream()) { var serializer = MessagePackSerializer.Create(dto.GetType()); serializer.PackTo(Packer.Create(ms), dto); var bytes = ms.ToArray(); var listenerResponse = (HttpListenerResponse)httpRes.OriginalResponse; listenerResponse.OutputStream.Write(bytes, 0, bytes.Length); httpRes.EndServiceStackRequest(); } } }); 

MessagePackSerializer Test

  [Test] public void test() { var arts = new List<Article>() { new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , new Article() {AR_CODEBARRE = "987654", AR_REF = "1002.ARRGHHH", AR_DESIGN = "BLAH BLAH TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "50FAM"} , new Article() {AR_CODEBARRE = "123456", AR_REF = "515.VEROTEST", AR_DESIGN = "THIS IS A TEST", CT_INTITULE = "ACME", FA_CODEFAMILLE = "10FAM"} , }; var serializer = MessagePackSerializer.Create<List<Article>>(); var ms = new MemoryStream(); serializer.PackTo(Packer.Create(ms), arts); ms.Position = 0; try { var obj = serializer.Unpack(ms); Assert.IsNotNull(obj); } catch (Exception ex) { throw ex; } ms.Close(); } 
+2
source

All Articles