2010-10-22 8 views
5

Meine App 'LocalClient' befindet sich in einem Firmen-LAN hinter einem HTTP-Proxy-Server (ISA). Der erste Azure-API-Aufruf, den ich mache - CloudQueue.CreateIfNotExist() - verursacht eine Ausnahme: (407) Proxyauthentifizierung erforderlich. Ich habe versucht, folgende Dinge:Verbindung mit Azure-Speicherkonto über Proxy-Server

Wie pro MSDN kann ein HTTP-Proxy-Server nur bei Entwicklung Storage (siehe http://msdn.microsoft.com/en-us/library/ee758697.aspx) in der Verbindungszeichenfolge angegeben werden:
UseDevelopmentStorage=true;DevelopmentStorageProxyUri= http://myProxyUri

Gibt es eine Möglichkeit zum Azure Storage verbinden durch ein Proxyserver?

Antwort

3

Die benutzerdefinierte Proxy-Lösung (die dritte Sache, die ich versuchte, wie in meiner ursprünglichen Frage erwähnt) funktionierte perfekt. Der Fehler, den ich vorher gemacht habe, war nicht das <configSections> Element am Anfang von <configuration> in app.config wie erforderlich zu setzen. Auf diese Weise löste die benutzerdefinierte Proxy-Lösung here mein Problem.

7

Ich fand tatsächlich, dass die benutzerdefinierte Proxy-Lösung nicht erforderlich war.

folgendes Hinzufügen app.config (kurz vor der </configuration>) hat für mich der Trick:

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

Ja, dass für die meisten Fällen funktionieren sollte, nehme ich an. Ich hatte das auch versucht. Aber in meinem Fall hat der Proxy-Server (Squid) den Benutzernamen ohne Domäne erwartet. Der angemeldete Benutzername, der an ihn gesendet wurde (gemäß der Einstellung 'useDefaultCredentials'), war im Format \ . Also würde es nicht authentifizieren. – amolbk

+0

Danke, deine Lösung hat mir geholfen! – codebot

+0

Dies funktionierte auch für mich (meine Anwendung war hängen, als ich versuchte, irgendwelche Operationen auf einem Tisch zu machen). – Adam

0

Um durch den Proxy passieren dann bitte wie unten verwenden, funktioniert es wie erwartet und die gleiche gewesen geprüft.

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 oder C# dann unter Code fügen Sie bitte "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>