2010-10-22 37 views
5

Ứng dụng 'LocalClient' của tôi nằm trong mạng LAN công ty phía sau máy chủ proxy HTTP (ISA). Lệnh gọi API Azure đầu tiên tôi thực hiện - CloudQueue.CreateIfNotExist() - gây ra một ngoại lệ: (407) Bắt buộc xác thực proxy. Tôi cố gắng điều sau đây:Kết nối với tài khoản lưu trữ Azure qua máy chủ proxy

Theo MSDN, một máy chủ proxy HTTP có thể được quy định trong chuỗi kết nối chỉ trong trường hợp lưu trữ phát triển (xem http://msdn.microsoft.com/en-us/library/ee758697.aspx):
UseDevelopmentStorage=true;DevelopmentStorageProxyUri= http://myProxyUri

Có cách nào để kết nối với các lưu trữ Azure thru máy chủ proxy?

Trả lời

3

giải pháp proxy tùy chỉnh (điều thứ ba tôi đã thử như đã đề cập trong câu hỏi ban đầu) đã hoạt động hoàn hảo. Sai lầm tôi đã làm trước đó đã không đưa các yếu tố <configSections> vào đầu <configuration> trong app.config theo yêu cầu. Khi làm điều đó, giải pháp proxy tùy chỉnh được cung cấp cho số here đã giải quyết được sự cố của tôi.

7

Tôi thực sự nhận thấy rằng không cần phải có giải pháp proxy tùy chỉnh.

Thêm dòng sau vào app.config (ngay trước khi </configuration>) đã làm các trick cho tôi:

<system.net> 
<defaultProxy enabled="true" useDefaultCredentials="true"> 
<proxy usesystemdefault="true" /> 
</defaultProxy> 
</system.net> 
+0

Vâng, đó là nên làm việc cho hầu hết các trường hợp, tôi giả sử. Tôi cũng đã thử điều đó. Nhưng trong trường hợp của tôi, máy chủ proxy (Squid) dự kiến ​​tên người dùng không có tên miền. Trong khi tên người dùng đăng nhập được gửi tới nó (theo cài đặt 'useDefaultCredentials') ở định dạng \ . Vì vậy, nó sẽ không xác thực. – amolbk

+0

Cảm ơn, giải pháp của bạn đã giúp tôi! – codebot

+0

Điều này cũng làm việc cho tôi (ứng dụng của tôi bị treo khi tôi cố gắng thực hiện bất kỳ thao tác nào trên bàn). – Adam

0

Để bởi vượt qua proxy thì hãy sử dụng như dưới đây, nó hoạt động như mong đợi và cùng đã được thử nghiệm.

public class AzureUpload { 

    // Define the connection-string with your values 
    /*public static final String storageConnectionString = 
     "DefaultEndpointsProtocol=http;" + 
     "AccountName=your_storage_account;" + 
     "AccountKey=your_storage_account_key";*/ 
    public static final String storageConnectionString = 
      "DefaultEndpointsProtocol=http;" + 
      "AccountName=test2rdrhgf62;" + 
      "AccountKey=1gy3lpE7Du1j5ljKiupjhgjghjcbfgTGhbntjnRfr9Yi6GUQqVMQqGxd7/YThisv/OVVLfIOv9kQ=="; 

    // Define the path to a local file. 
    static final String filePath = "D:\\Project\\Supporting Files\\Jar's\\Azure\\azure-storage-1.2.0.jar"; 
    static final String file_Path = "D:\\Project\\Healthcare\\Azcopy_To_Azure\\data"; 

    public static void main(String[] args) { 
     try 
     { 
      // Retrieve storage account from connection-string. 
      //String storageConnectionString = RoleEnvironment.getConfigurationSettings().get("StorageConnectionString"); 
      //Proxy httpProxy = new Proxy(Proxy.Type.HTTP,new InetSocketAddress("132.186.192.234",8080)); 
      System.setProperty("http.proxyHost", "102.122.15.234"); 
      System.setProperty("http.proxyPort", "80"); 
      System.setProperty("https.proxyUser", "ad001\\empid001"); 
      System.setProperty("https.proxyPassword", "pass!1"); 
      // Retrieve storage account from connection-string. 
      CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); 

      // Create the blob client. 
      CloudBlobClient blobClient = storageAccount.createCloudBlobClient(); 


      // Get a reference to a container. 
      // The container name must be lower case 
      CloudBlobContainer container = blobClient.getContainerReference("rpmsdatafromhospital"); 

      // Create the container if it does not exist. 
      container.createIfNotExists(); 

      // Create a permissions object. 
      BlobContainerPermissions containerPermissions = new BlobContainerPermissions(); 

      // Include public access in the permissions object. 
      containerPermissions.setPublicAccess(BlobContainerPublicAccessType.CONTAINER); 

      // Set the permissions on the container. 
      container.uploadPermissions(containerPermissions); 

      // Create or overwrite the new file to blob with contents from a local file. 
      /*CloudBlockBlob blob = container.getBlockBlobReference("azure-storage-1.2.0.jar"); 
      File source = new File(filePath); 
      blob.upload(new FileInputStream(source), source.length());*/ 

      String envFilePath = System.getenv("AZURE_FILE_PATH"); 

      //upload list of files/directory to blob storage 
      File folder = new File(envFilePath); 
      File[] listOfFiles = folder.listFiles(); 

      for (int i = 0; i < listOfFiles.length; i++) { 
       if (listOfFiles[i].isFile()) { 
       System.out.println("File " + listOfFiles[i].getName()); 

       CloudBlockBlob blob = container.getBlockBlobReference(listOfFiles[i].getName()); 
       File source = new File(envFilePath+"\\"+listOfFiles[i].getName()); 
       blob.upload(new FileInputStream(source), source.length()); 
       System.out.println("File " + listOfFiles[i].getName()+ " upload successful"); 

       } 
       //directory upload 
       /*else if (listOfFiles[i].isDirectory()) { 
       System.out.println("Directory " + listOfFiles[i].getName()); 

       CloudBlockBlob blob = container.getBlockBlobReference(listOfFiles[i].getName()); 
       File source = new File(file_Path+"\\"+listOfFiles[i].getName()); 
       blob.upload(new FileInputStream(source), source.length()); 
       }*/ 
      } 

     }catch (Exception e) 
     { 
      // Output the stack trace. 
      e.printStackTrace(); 
     } 
    } 
} 

Net hoặc C# sau đó xin vui lòng thêm bên dưới mã để "App.config"

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <startup> 
     <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> 
    </startup> 

    <system.net> 
    <defaultProxy enabled="true" useDefaultCredentials="true"> 
     <proxy usesystemdefault="true" /> 
    </defaultProxy> 
    </system.net> 

</configuration> 
Các vấn đề liên quan