Best practice for handeling big imports over WCF?
I have had some trouble when implementing eg. an import rutine that parses files on the silverlight client and sends a huge amount of objects to a WCF servic开发者_开发百科e using basicHttpBinding.
I have set the maxBufferSize, maxRecieveSize etc to the maximum values, but unless I chunk up the collection of objects myself in code and make several calls it just fails.
So I am wondering if any of you have some experience with good ways of doing calls with huge collections of objects?
The same thing happened to my team...except we weren't working in SL, we were in WPF.
I know this isn't the most glamorous way, but my team and I have also had a lot of success taking the text file, converting to a byte array and then sending the byte array across the wire. It turns out that WCF is extremely efficient with an array of bytes.
To read in the file, we do this on the client:
fileByteArray = File.ReadAllBytes(fileLocation);
And then our service interface looked like this:
[ServiceContract]
public class IImport
{
[OperationContract]
BulkResults ImportFromFile(byte[] importFile);
}
We've also tried the Buffered/Streamed approach too, and we've switched all our services over to Streaming. This also helped with memory consumption.
Christian, I had some good experience playing with the TransferMode
. It is buffered
by default.
Changing to StreamedResponse
in my case allowed me to return big set of data without heavy memory consumptions.
More here:
http://msdn.microsoft.com/en-us/library/system.servicemodel.transfermode.aspx
http://blogs.msdn.com/b/carlosfigueira/archive/2010/07/08/using-transfermode-streamedresponse-to-download-files-in-silverlight-4.aspx
精彩评论