开发者

Silverlight 3: How to retrieve large(approx: 50 MB) xml string from ASP.NET webpage?

What is the preferred way to retrieve large(approx: 50 MB) xml string from ASP.NET webpage?

Placing the xml string in file and downloading the file is not a choice.(This should be my last resort if nothing else wo开发者_开发技巧rks)

I have following method on ASP.NET server which is exposed through WCF service to silverlight client.

[OperationContract]
public string GetXmlDataByRegion(string region)
{
   //Fetch Xml string from database based on given region name     
}

Unfortunately these xml strings are approximately 50MB to 100 MB. Silverlight client needs to retrive these large strings and store it in a file on the client machine at the path selected by the user through saveFileDialog.

My concern is WCF service will not allow such large messages. How can I address this issue? Any ideas?


You can do it, you'll just need to bump up the MaxReceivedMessageSize, maxBufferSize, maxBufferPoolSize, and potentially others - keep bumping them up until you're successful.

This will permit large files to be sent and received, but you need to open up both ends to expect it.

You can also use a Binary message encoding (if you're not already), even in Silverlight. This will result in smaller messages than plain text.

For example:

        <binding name="ObjectServicePortBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:30:00" sendTimeout="00:01:00" maxBufferSize="1048576" maxBufferPoolSize="5242880" maxReceivedMessageSize="52428800" transferMode="Buffered" useDefaultWebProxy="true">
      <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
      <security mode="None">
        <transport clientCredentialType="None" proxyCredentialType="None" realm="" />
        <message clientCredentialType="UserName" algorithmSuite="Default" />
      </security>
    </binding>

Edit: Streaming of data may be the more appropriate approach:

  • Streamed: Both in and out messages are streamed
  • StreamedRequest: Messages sent from client to server are streamed
  • StreamedRespone: Only messages returned from the server to the client are streamed
  • Buffered: This is the default of buffering all data and sending it in one burst

http://msdn.microsoft.com/en-us/library/ms731913.aspx

  • Buffered transfers hold the entire message in a memory buffer until the transfer is complete. A buffered message must be completely delivered before a receiver can read it.

  • Streamed transfers expose the message as a stream. The receiver starts processing the message before it is completely delivered.


You can use a ASHX generic handler for this and make a straightforward http request with the WebClient for it. Although I'm not sure that this is the preferred way, it will work as a solution.


Have you considered sending a compressed byte array instead?

A 50MB XML file might go down to 5MB (assuming 90% compression) - a significant drop in traffic and transfer time (excluding the time to compress/decompress at both ends)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜