3

I'm working on a silverlight reporting tool which draws up all sorts of fancy graphs based on client data. The issue I'm having right now is a good way to get all the data I need from the database to my silverlight app.

Sofar I have a web service which chunks up my data into groups of 1000 and ships them back to me. I need a bit over 3000 records, which calls for about 4 calls to the web service at 2 seconds a piece. Needless to say, it's slower than I'd want it to be.

I currently have these set:


binding.MaxBufferSize = 2147483647;
binding.MaxReceivedMessageSize = 2147483647;

I'm sure someone has a better way to grab db data that's faster. At the very least, a way that would let me get all my data in one try.

Buddy Lee
  • 376
  • 2
  • 13

1 Answers1

1

It (based in part on the earlier question) sounds like bandwidth is the issue; I would give serious thought to trying protobuf-net; the "protocol buffers" format designed by Google is very efficient (much more so that the default DataContractSerializer), and it can be used very conveniently from .NET. Ideal for bandwidth-related scenarios. The only glitch is that currently the WCF hooks don't work with Silverlight (so you can't just add an attribute / config entry), but you can pass the data as a byte[] easily enough (just return byte[] from a method).

For example; if you have a record like:

[ProtoContract]
public class MyRecord {
    [ProtoMember(1)]
    public int Id {get;set;}

    [ProtoMember(2)]
    public string Description {get;set;}

    // etc
}

and a List<MyRecord>, then you should be able to use:

byte[] result;
using(MemoryStream ms = new MemoryStream()) {
    Serializer.Serialize(ms, list); // or maybe (list, ms) ;-p
    result = ms.ToArray();
}

I've also seen somebody return a Stream on the operation-contract (rather than a byte[]) - which seemed to work better with MTOM (hint: you definitely want to enable MTOM if possible when passing raw binary).

Community
  • 1
  • 1
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • The issue would come on the silverlight side. Right now I don't believe there is a simple way of retrieving the serialized info. The BinarySerializer isn't part of the silverlight framework. – Buddy Lee Sep 22 '09 at 21:48
  • Also from the looks of it, the transport latency isn't too bad. The app will run close to the db. Trick would be finding a way to get all the data in one swoop, rather than having to go back 4 times, which is causing my 8 second delay. – Buddy Lee Sep 22 '09 at 21:50
  • Which is why I didn't mention `BinaryFormatter`; I mentioned an alternative (and more efficient) binary serializer that *does* work in both regular and Silverlight; http://code.google.com/p/protobuf-net/ – Marc Gravell Sep 22 '09 at 22:15
  • 1
    4 calls is trivial if latency is low; it sounds more like bandwidth to me...? – Marc Gravell Sep 22 '09 at 22:16