Azure WCF 服务在 Blob 存储文件上出错

本文关键字:存储文件 出错 Blob WCF 服务 Azure | 更新日期: 2023-09-27 18:33:15

我有一个Windows Azure项目,其中WCF服务作为WebRole。我在 Azure 中有一个存储帐户,我想在其中保存文件。

我的代码在我使用 Azure 模拟器进行测试时工作。

但要知道我遇到了下一个错误:

Could not find a part of the path 'C:'temp'BatchAzure.log'.

我尝试执行的客户端服务:

    string path = @"C:'temp'BatchAzure.log";
    var test = service.SaveGezichtBestand(path, "999999");

我正在使用的方法:

public bool SaveGezichtBestand(string filePath, string memberID)
        {
            bool result = false;
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
            RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString"));
            CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
            // Retrieve a reference to a container 
            CloudBlobContainer container = blobClient.GetContainerReference("facefileblobcontainer");
            // Create the container if it doesn't already exist
            container.CreateIfNotExist();
            //By default, the new container is private, so you must specify your storage account key (as you did above) 
            //to download blobs from this container.
            container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob });
            // Retrieve reference to a blob named "myblob"
            CloudBlob blob = container.GetBlobReference(memberID);
            try
            {
                // Create or overwrite the "myblob" blob with contents from a local file
                using (var fileStream = System.IO.File.OpenRead(filePath))
                {
                    blob.UploadFromStream(fileStream);
                    result = true;
                }
            }
            catch (Exception)
            {
                result = false;
                throw;
            }
            return result;
        }

Azure WCF 服务在 Blob 存储文件上出错

![在此处输入图像描述][1]嗨

我假设 SaveGezichtBestand 方法是在 WindowsAzure 上运行的 wcf 服务的方法。在这种情况下,C 盘除了 azure deoyment 服务为你创建的目录外,没有任何目录。如果不打算写入承载 Webrole 的 VM 上的光盘(在 WCF 服务中),则必须在启动任务中创建目录In de *.csdef configation

您还必须将目录 .cmd 文件添加到 wcf 项目中

请注意,在

Azure 回收 VM 期间,VM 的本地磁盘上的任何数据都将丢失。

Azure traings 工具包演示"WebAndWorkerRoleEnhancements"中的详细信息

米歇尔

我不肯定我跟随你的情况,所以回顾一下......

服务最初在本地工作,但现在已部署到 Azure,则无法正常工作。 你正在从本地客户端使用 Web 服务(不在 Azure 上,尤其是不在 Web 角色上)。

基于上述问题,问题是您将本地文件路径传递到 Azure,其中 Web 角色尝试使用您的路径访问其自己的文件系统上的文件。 若要解决此问题,需要将实际文件传递到 Azure(而不仅仅是路径)。 可以使用流或字节数组。