2016-10-10 14 views
0

シンプルなコンソールアプリケーションを作成し、これをAzure webjobとして実行して、以下のエラーが表示されました。同じコードがローカルで正常に動作しています。エラーシンプルコンソールアプリケーションをAzure webjobとして実行中

[10/10/2016 18:15:48 > 494acb: SYS INFO] Status changed to Initializing [10/10/2016 18:15:48 > 494acb: SYS INFO] Run script 'ConsoleApplication1.exe' with script host - 'WindowsScriptHost' [10/10/2016 18:15:48 > 494acb: SYS INFO] Status changed to Running [10/10/2016 18:15:49 > 494acb: ERR ] [10/10/2016 18:15:49 > 494acb: ERR ] Unhandled Exception: Microsoft.WindowsAzure.Storage.StorageException: The remote server returned an error: (400) Bad Request. ---> System.Net.WebException: The remote server returned an error: (400) Bad Request. [10/10/2016 18:15:49 > 494acb: ERR ] at System.Net.HttpWebRequest.GetResponse() [10/10/2016 18:15:49 > 494acb: ERR ] at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext) [10/10/2016 18:15:49 > 494acb: ERR ] --- End of inner exception stack trace --- [10/10/2016 18:15:49 > 494acb: ERR ] at Microsoft.WindowsAzure.Storage.Core.Executor.Executor.ExecuteSync[T](RESTCommand 1 cmd, IRetryPolicy policy, OperationContext operationContext) [10/10/2016 18:15:49 > 494acb: ERR ] at Microsoft.WindowsAzure.Storage.Table.TableOperation.Execute(CloudTableClient client, CloudTable table, TableRequestOptions requestOptions, OperationContext operationContext) [10/10/2016 18:15:49 > 494acb: ERR ] at Microsoft.WindowsAzure.Storage.Table.CloudTable.Execute(TableOperation operation, TableRequestOptions requestOptions, OperationContext operationContext) [10/10/2016 18:15:49 > 494acb: ERR ] at ConsoleApplication1.Program.getStockPriceFromGoogle() [10/10/2016 18:15:49 > 494acb: ERR ] at ConsoleApplication1.Program.Main(String[] args) [10/10/2016 18:15:49 > 494acb: SYS INFO] Status changed to Failed [10/10/2016 18:15:49 > 494acb: SYS ERR ] Job failed due to exit code -532462766

コンソールアプリケーションコード:

class Program 
{ 
    static void Main(string[] args) 
    { 
     getStockPriceFromGoogle(); 
    } 

    public static void getStockPriceFromGoogle() 
    { 

     try 
     { 
      CloudStorageAccount storageAcount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString")); 
      CloudTableClient tableClient = storageAcount.CreateCloudTableClient(); 
      CloudTable googleStockTable = tableClient.GetTableReference("GoogleStock"); 
      googleStockTable.CreateIfNotExists(); 

      const string tickers = "RELIANCE,SBIN"; 
      string json = null; 

      try 
      { 
       using (var web = new WebClient()) 
       { 
        var url = $"http://finance.google.com/finance/info?client=ig&q=NSE%3A{tickers}"; 
        json = web.DownloadString(url); 
       } 
      } 
      catch (Exception ex) 
      { 
       Trace.WriteLine("Error calling Google service , error :" + ex.ToString()); 
      } 

      //Google adds a comment before the json for some unknown reason, so we need to remove it 
      json = json.Replace("//", ""); 

      var v = JArray.Parse(json); 

      foreach (var i in v) 
      { 
       var ticker = i.SelectToken("t"); 
       var price = (decimal)i.SelectToken("l"); 

       GoogleStock googleStock = new GoogleStock(ticker.ToString(), DateTime.Now) 
       { 
        Price = price, 
        PriceInLocalCurrency = i.SelectToken("l_cur").ToString(), 

        id = (int)i.SelectToken("id"), 
        Exchange = i.SelectToken("e").ToString(), 
        Chanage = (float)i.SelectToken("c"), 
        ChnagePersontage = (float)i.SelectToken("cp"), 
        LastTradeTime = (DateTime)i.SelectToken("lt_dts"), 

       }; 

       try 
       { 
        TableOperation insertOperation = TableOperation.Insert(googleStock); 
        googleStockTable.Execute(insertOperation); 
       } 
       catch (Exception ex) 
       { 
        Trace.WriteLine("Error When saving data , error :" + ex.ToString()); 
        throw; 
       } 

       Console.WriteLine($"{ticker} : {price}"); 
      } 
     } 
     catch (Exception ex) 
     { 
      Trace.WriteLine("Error When saving data , error :" + ex.ToString()); 
      throw; 
     } 
    } 
} 

class GoogleStock : TableEntity 
{ 
    public GoogleStock(string StockName, DateTime InsertionDate) 
    { 
     this.PartitionKey = StockName; 
     this.RowKey = InsertionDate.ToUniversalTime().ToString(); 
    } 

    public int id { get; set; } 

    public string StockName { get; set; } 

    public string Exchange { get; set; } 

    public decimal Price { get; set; } 

    public string PriceInLocalCurrency { get; set; } 

    public DateTime LastTradeTime { get; set; } 

    public float Chanage { get; set; } 

    public float ChnagePersontage { get; set; } 
} 

に私は紺碧のポータルでは、キー、まだ助けを設定するアプリを追加しました。

+0

ストレージ例外が発生しているようです。最初のステップは、[このページ](https://github.com/projectkudu/kudu/wiki/Isolating-WebJobs-and-Deployment-script-issues)に従って、WebJobを伴わない単純なシナリオに分離することです。 –

答えて

2

多くの場合、factorsは、テーブルサービスの操作を実行すると400の不正なリクエストエラーが発生する可能性があります。たとえば、プロパティ名が無効である、指定された値が無効であるなど

Same code working fine in local.

私は私の地元にあなたのコードをテストし、あなたのコードは、私の地元に(それが400不正な要求エラーを返します)動作しません。私はdatetimeベースの行キー(this.RowKey = InsertionDate.ToUniversalTime().ToString();)を使用すると、このタイプの問題が発生する可能性があります。行キーの値は、ローカルで10/11/2016 3:14:03 AM(スラッシュ(/)文字を使用)のようになります。ただし、スラッシュ(/)文字はPartitionKeyプロパティとRowKeyプロパティの値には使用できません。 「Characters Disallowed in Key Fields」にチェックを入れてください。

Ticksの現在の時間値をRow Key値として使用して、次のコードを使用できます。

this.RowKey = InsertionDate.Ticks.ToString("d19"); 

以外にも、あなたは日時に基づいてパーティション・キーを生成するために2つのアプローチを説明しthis articleをチェックすることができます。

+0

ありがとうございました。私はToFileTimeUtc "InsertionDate.ToFileTimeUtc()。ToString();"を使用しました。 。ちょうど情報のために私の地元で働いていた、それはこの'10 -10-2016 15:27:03 'のように来る価値がある、私は " - "が有効な文字だと思う。 –

関連する問題