Azure blob下载被阻止

时间:2014-03-24 14:16:31

标签: azure azure-storage

我正在从Web应用程序下载大型Azure blob(6 GB)。 大约40分钟后,blob成功下载到Web服务器,但应用程序在下载blob的WCF代码行中被阻止,然后发出超时异常。我文件较小我没有这个问题。

以下是代码:

MVC控制器:

        timeoutMinutes = 60;

        BasicHttpBinding binding = new BasicHttpBinding();
        EndpointAddress address = new EndpointAddress(EndPoint);
        factory = new ChannelFactory<RemotingServiceLibrary.IRemotingService>(binding, address);
        factory.Endpoint.Binding.SendTimeout = new TimeSpan(0, timeoutMinutes, timeoutSeconds);
        IRemotingService channel = factory.CreateChannel();

        channel.LoadBlob(containerName, blobName, sqlMachineBackupFile, connectionString);

WCF:

    public string LoadBlob(string blobContainer, string blobName, string DestinationFilePath, string connectionString)
    {
        try
        {
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            CloudBlobContainer container = blobClient.GetContainerReference(blobContainer);
            CloudBlockBlob blob = container.GetBlockBlobReference(blobName);

            int segmentSize = 1 * 1024 * 1024;

            blob.FetchAttributes();
            var blobLengthRemaining = blob.Properties.Length;
            long startPosition = 0;
            do
            {
                long blockSize = Math.Min(segmentSize, blobLengthRemaining);
                byte[] blobContents = new byte[blockSize];
                using (MemoryStream ms = new MemoryStream())
                {
                    blob.DownloadRangeToStream(ms, startPosition, blockSize);
                    ms.Position = 0;
                    ms.Read(blobContents, 0, blobContents.Length);
                    using (FileStream fs = new FileStream(DestinationFilePath, FileMode.OpenOrCreate))
                    {
                        fs.Position = startPosition;
                        fs.Write(blobContents, 0, blobContents.Length);
                    }
                }
                startPosition += blockSize;
                blobLengthRemaining -= blockSize;
            }
            while (blobLengthRemaining > 0);

        }
        catch (Exception ex)
        {
            return ex.Message;
        }
        return "OK";
    }            

提前致谢

0 个答案:

没有答案