简体   繁体   English

Azure Worker角色和Blob存储C#-Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(400)错误的请求

[英]Azure Worker role and blob storage c# - Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request

I have uploaded files in blob storage. 我已将文件上传到Blob存储中。 I am trying to download those files from worker role to do some processing on it. 我正在尝试从辅助角色下载这些文件以对其进行一些处理。 The container name is sent from the WebApi2 to the queue. 容器名称从WebApi2发送到队列。

The worker role first fetches the container name from the queue and then tries to download the blobs within that container. worker角色首先从队列中获取容器名称,然后尝试下载该容器中的blob。

Below is the code for the name: 以下是名称的代码:

  public override void Run()
    {
        Trace.WriteLine("Starting processing of messages");

        // Initiates the message pump and callback is invoked for each message that is received, calling close on the client will stop the pump.
        Client.OnMessage((receivedMessage) =>
        {
            try
            {
                // Process the message
                Trace.WriteLine("Processing Service Bus message: " + receivedMessage.SequenceNumber.ToString());
                string msg = "Container Name: " + receivedMessage.GetBody<String>();
                Trace.WriteLine("Processing Service Bus message: " + msg);

                CloudStorageAccount storageAccount =   CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("MyStorage"));


                CloudBlobContainer imagesContainer = null;


                CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

                imagesContainer = blobClient.GetContainerReference(msg);


                // Create the container if it doesn't already exist.
                imagesContainer.CreateIfNotExists();


                imagesContainer.SetPermissions(new BlobContainerPermissions
                {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });

                var blobs = imagesContainer.ListBlobs();
                var listOfFileNames = new List<string>();


                foreach (var blob in blobs)
                {
                    var blobFileName = blob.Uri.Segments.Last();
                    listOfFileNames.Add(blobFileName);
                    Trace.WriteLine(listOfFileNames);
                }

                if (listOfFileNames == null)
                {

                    Trace.WriteLine("present");
                }



                for (i = 1; i < 3; i++)
                {
                    CloudBlockBlob signBlob =    imagesContainer.GetBlockBlobReference(i + ".txt");

                    MemoryStream lms = new MemoryStream();
                    signBlob.DownloadToStream(lms);
                    lms.Seek(0, SeekOrigin.Begin);

                    StreamReader SR = new StreamReader(lms);
                    Trace.WriteLine(SR);
                }


            }




            catch(Microsoft.WindowsAzure.Storage.StorageException e)
            {
                // Handle any message processing specific exceptions here
                Trace.WriteLine("Error:" + e);
            }
        });

        CompletedEvent.WaitOne();
    }

I am getting the below Exception: 我收到以下异常:

enter code hereException thrown: 'Microsoft.WindowsAzure.Storage.StorageException' in Microsoft.WindowsAzure.Storage.dll

Error:Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request. 错误:Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(400)错误的请求。 ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. ---> System.Net.WebException:远程服务器返回错误:(400)错误的请求。 at System.Net.HttpWebRequest.GetResponse() at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Executor\\Executor.cs:line 677 --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Executor\\Executor.cs:line 604 at Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists(BlobContainerPublicAccessType accessType, BlobRequestOptions requestOptions, OperationContext operationContext) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Blob\\CloudBlobContainer.cs:line 199 at WorkerRoleWithSBQueue1.WorkerRole.b__4_0(BrokeredMessage 在System.Net.HttpWebRequest.GetResponse()在Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync [T](RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext) in c:\\Program Files (x86)\\Jenkins\\workspace\\release_dotnet_master\\Lib\\ClassLibraryCommon\\Core\\Executor\\Executor.cs:line 677 --- End of inner exception stack trace --- at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand 1 C:\\ Program Files(x86)\\ Jenkins \\ workspace \\ release_dotnet_master \\ Lib \\ ClassLibraryCommon \\ Core \\ Executor \\ Executor.cs:行604中的cmd,IRetryPolicy策略,OperationContext operationContext):Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer.CreateIfNotExists (C:\\ Program Files(x86)\\ Jenkins \\ workspace \\ release_dotnet_master \\ Lib \\ ClassLibraryCommon \\ Blob \\ CloudBlobContainer.cs:Line 199中的BlobContainerPublicAccessType accessType,BlobRequestOptions requestOptions,OperationContext operationContext):WorkerRoleWithSBQueue1.WorkerRole.bred_4_0上的199行 receivedMessage) receiveMessage)

Any help would be highly appreciated. 任何帮助将不胜感激。

Looking at your code, you're doing the following: 查看您的代码,您正在执行以下操作:

string msg = "Container Name: " + receivedMessage.GetBody<String>();

And then you're doing the following: 然后您要执行以下操作:

        imagesContainer = blobClient.GetContainerReference(msg);
        // Create the container if it doesn't already exist.
        imagesContainer.CreateIfNotExists();

So basically you're creating a container name of which starts with Container Name which is an invalid value for the container name. 因此,基本上,您正在创建一个容器名称,该名称以“容器名称”开头,这是该Container Name的无效值。 This is why you're getting the error. 这就是为什么您得到错误。

Please see this link for valid naming convention for blob container: https://msdn.microsoft.com/en-us/library/azure/dd135715.aspx . 请参阅此链接以获取Blob容器的有效命名约定: https : //msdn.microsoft.com/zh-cn/library/azure/dd135715.aspx

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Microsoft.WindowsAzure.Storage.StorageException:远程服务器返回错误:(404)Not Found - Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (404) Not Found Microsoft.WindowsAzure.Storage.StorageException:无法连接到远程服务器 - Microsoft.WindowsAzure.Storage.StorageException: Unable to connect to the remote server 无法上传到 azure Blob 存储:远程服务器返回错误:(400) 错误请求 - Cannot upload to azure Blob Storage: The remote server returned an error: (400) Bad Request Microsoft.WindowsAzure.Storage.dll中出现“Microsoft.WindowsAzure.Storage.StorageException”类型的第一次机会异常 - A first chance exception of type 'Microsoft.WindowsAzure.Storage.StorageException' occurred in Microsoft.WindowsAzure.Storage.dll Microsoft.WindowsAzure.Storage.StorageException 无法加载文件或程序集 &#39;Newtonsoft.Json,版本 = 6.0.0.0, - Microsoft.WindowsAzure.Storage.StorageException Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, C#FCM:远程服务器返回错误:(400)错误的请求 - C# FCM : The remote server returned an error: (400) Bad Request Azure Blob存储400错误请求 - Azure Blob Storage 400 Bad Request 远程服务器返回错误:C# 代码中的 (400) 错误请求 - The remote server returned an error: (400) Bad Request in C# Code 远程服务器返回错误:(400)错误的请求C# - The remote server returned an error: (400) Bad Request C# Microsoft.WindowsAzure.Storage 4.0.1和Windows Storage Emulator 3.1.0导致(400)错误请求 - Microsoft.WindowsAzure.Storage 4.0.1 and Windows Storage Emulator 3.1.0 results in (400) Bad Request
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM