2017-05-20 58 views
0

我有一個使用ASP.NET 4.5/C#構建的Web應用程序,並以Azure作爲Web App託管。該網站允許用戶上傳PDF文件,然後將其存儲在天藍色的blob容器中,然後可以根據需要通過網站下載。到目前爲止這麼好,一切都很好。使用Azure Web應用程序前端對存儲在azure blob存儲中的PDF文件運行自定義可執行文件

我們現在有一個新的需求,它涉及使用自定義win32可執行文件處理這些文件,並且網站必須知道處理是否成功。這個exe文件有一個安裝文件,必須安裝在目標機器上才能使用。

我一直在摸索如何構建這個功能。我遇到了很多文章,這些文章告訴我們需要工作者角色,或者需要虛擬機。但是所有文章看起來都很抽象。

鑑於可執行文件的安裝程序需要人工干預,我認爲Azure虛擬機是最佳選擇。但是,Web應用程序將如何與此交流。我該如何通知網絡應用程序的結果?

回答

0

由於Web應用程序是沙盒,因此無法在Azure Web App中安裝此類軟件。因此,您將無法運行該設置exe

對於這樣的處理,您需要在虛擬機或web/worker角色中運行應用程序的這一部分。

0

但是,Web應用程序如何與此進行通信。我該如何通知網絡應用程序的結果?

Azure Queue storage可以滿足您的要求。它可以在應用程序組件之間提供雲消息。您的虛擬機可以將處理結果寫入隊列,並且您的Web應用程序可以從同一隊列中讀取處理結果。

要將新消息添加到隊列中,您可以參考以下代碼。

// Retrieve storage account from connection string. 
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
    CloudConfigurationManager.GetSetting("StorageConnectionString")); 

// Create the queue client. 
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); 

// Retrieve a reference to a queue. 
CloudQueue queue = queueClient.GetQueueReference("myqueue"); 

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

// Create a message and add it to the queue. 
CloudQueueMessage message = new CloudQueueMessage("Hello, World"); 
queue.AddMessage(message); 

在你的Web應用程序,你如果有新的消息已被添加到隊列中可以創建一個QueueTrigger WebJob,作業將被立即執行。

public static void ProcessQueueMessage([QueueTrigger("myqueue")] string processResult, TextWriter log) 
{ 
    //You can get the processResult and do anything needed here 
}