Silverlight数据访问 [英] Silverlight data access

查看:72
本文介绍了Silverlight数据访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Silverlight报告工具,该工具可以根据客户数据绘制各种奇特的图表。我现在遇到的问题是将所需的所有数据从数据库获取到Silverlight应用程序的好方法。

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.

到目前为止,我有一个Web服务将我的数据分成1000组,然后将它们发回给我。我需要超过3000条记录,每条记录在2秒内需要约4次对Web服务的调用。不用说,它比我想要的要慢。

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.

我目前有以下设置:


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.

推荐答案

It(部分基于先前的问题)听起来像是带宽问题;我会认真考虑尝试使用protobuf-net。 Google设计的协议缓冲区格式非常高效(很多,因此默认的 DataContractSerializer ),并且可以从以下位置非常方便地使用。净。带宽相关方案的理想选择。唯一的问题是,当前WCF挂钩不适用于Silverlight(因此您不能仅添加属性/配置条目),但是您可以 将数据作为 byte [] 很容易(只需从方法中返回 byte [] )。

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
}

List< MyRecord> ,那么您应该可以使用:

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

我也看到有人返回 Stream 上的操作合同(而不是 byte [] )-与MTOM一起使用似乎更好(提示:如果您确实希望启用MTOM,传递原始二进制文件时可能会发生)。

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

这篇关于Silverlight数据访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆