2

使用 WCF 端点通过 HTTP 传输 SQL 表格数据的最快方法是什么?

现在我正在使用 ESQL 查询实体框架,然后将 DataTable 结果序列化为一个字节 [],然后将其发送过来,然后在另一端反序列化,这似乎很慢。现在,15000 多行的序列化数据的大小约为 4000 字节。我还尝试了 OData 服务,但这也很慢。

与 JSON 相比,我认为它是最快的 - 一个仅包含 1048 个 SQL 行的 JSON 文件大约有 200000 个字节。数据大小与通过 HTTP 传输的速度之间是否存在直接关联?(似乎很直观,但我并不积极)。

最快的格式是什么?我正在考虑使用 SQLDataReader 到 JSON 并将 JSON 发送过来,我认为它应该表现良好,但我不确定。这仅用于数据同步目的。

谢谢。

编辑 做了一些更多的跟踪,看起来我的一些初始测量是错误的。请参阅下面的相应方法(以毫秒为单位)。

2011 年 7 月 11 日星期一下午 6:42:23: :函数“反序列化”持续时间。已用时间:481 毫秒

2011 年 7 月 11 日星期一下午 6:42:23 : : 函数“HttpRequest”持续时间。已用时间:4776 毫秒

2011 年 7 月 11 日星期一下午 6:42:22::DataTable 长度(字节)= 13047247 字节

上面引用的 DataTable 包含约 7000 行,看起来很陡峭,对吧?

4

1 回答 1

1

The SqlDataReader is the fastest method for getting data out of the database, yes. The trouble you're going to have then is that you're going to need to assemble your result in full before sending it out over HTTP. You cannot just stream the result as it's read from the database. JSON is a reasonably tight way of representing data, but since you'll have to repeat the column names over and over, you'd be much better off with a simple plain text tab separated value file. Set you Content-type = text/plain and scrub any tabs out of your data when you get it from the SqlDataReader. You might also want to consider gzipping your result - depending on the speed of your network vs your web server's processing power.

-- EDIT --

As Sean rightly pointed out, the plain text option isn't a WCF solution.

于 2011-07-12T01:57:44.847 回答