开发者

When should I consider changing the return type of my service?

开发者 https://www.devze.com 2023-04-06 03:37 出处:网络
We have a WCF service that returns a byte array from a SQL Server database. This byte array usually represents reports but, in the future, may be Word or Excel documents. Currently, the files returned

We have a WCF service that returns a byte array from a SQL Server database. This byte array usually represents reports but, in the future, may be Word or Excel documents. Currently, the files returned are a开发者_StackOverflow社区round 300K but some approach 900K. The future office documents would fall into a similiar size range.

At what point should we consider changing the return type or is a byte[] just fine? The second part to the question is, if we should change it, what do we chagne it to? Should we consider streaming or its that not appropriate for this type of file?


if you are using this WCF service to download data from a server to a client, like a web browser, streaming is probably a good idea so no where in the chain the whole chunk of data is allocated in memory at once.

see here for extensive documentation and an example on this subject: How to: Enable Streaming

I also suggest to do not break the ServiceContract if you are already providing a byte[] in return from some methods, it's not a good practice to force all clients to be rewritten, just add the new method side by side, if possible and convenient.


I would carefully look at the performance of your WCF service, using a profiler or by stress testing it. I wouldn't change it until it becomes necessary, but you aren't too far off.

To stream the data, you would change your contract to return a Stream (or implement a new contract to avoid breaking an existing one), and set your Transfer Mode to Streamed. There is a very nice write-up of the pros and cons, and how-tos of all of that here.

0

精彩评论

暂无评论...
验证码 换一张
取 消