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