2012-05-04 58 views
1

我有一个WCF服务作为WebRole的Windows Azure项目。 我在Azure中有一个存储帐户,我想在其上保存文件。Azure WCF服务在BLOB存储文件上给出错误

我的代码在我使用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; 
     } 

回答

1

! [请在此输入图片] [1]您好

我假设SaveGezichtBestand方法是在WindowsAzure上运行的wcf服务的一种方法。在这种情况下,C驱动器没有任何其他目录,而是天蓝色的服务为您创建的目录。如果你不会写在承载您的Webrole(TIS中的情况下,WCF服务)的虚拟机磁盘必须在德* .csdef configation建立在你的启动任务 目录

您还可以到directorys.cmd文件添加到您的WCF项目

Remeber该VM中的localdisks任何数据将由Azure的虚拟机的循环过程中丢失。在Azure中traings套件演示

更多信息“WebAndWorkerRoleEnhancements”

米希尔

1

我还不能肯定我按照你的情况可以这么概括...

你的服务,最初的工作在当地,但现在你已经部署到天蓝了,但它没有。您正在使用本地客户端的Web服务(不是基于Azure,特别是不在Web角色上)。

基于上述问题,您正在将本地文件路径传递至azure,您的webrole正尝试使用您的路径在其自己的文件系统上访问该文件。为了解决这个问题,你需要将实际的文件传递给azure(而不仅仅是路径)。您可以使用流或字节数组。