我有一個asp.net mvc站點部署在天藍色的按需web作業。網絡作業嘗試使用sendgrid發送電子郵件。Azure按需web作業沒有收到正確格式化的json序列化字符串
我的網站的用戶填寫表格,可選附加文件,然後單擊發送。服務器端我收集所有數據使用Newtonsoft.Json將其序列化爲json。我的網絡應用程序和網絡作業都使用相同版本的Newtonsoft.Json。
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net47" />
然後我使用後的參數
private static void TrySendEmail(Customer customer)
{
using (WebClient client = new WebClient())
{
string responsebody = Encoding.UTF8.GetString(client.UploadValues(ConfigurationManagerExtension.WebJobUrl,
"POST",
new System.Collections.Specialized.NameValueCollection
{
{"email",JsonConvert.SerializeObject(CreateCustomerEmail(customer)) }
}));
}
}
序列化的數據到我的webjob序列化的數據得到由我webjob它試圖利用Newtonsoft.Json反序列化,並使用sendgrid發送電子郵件收到
在azure上運行web作業時出現錯誤未處理的異常:System.AggregateException:發生了一個或多個錯誤。 ---> Newtonsoft.Json.JsonReaderException:無效的JavaScript屬性標識符字符:}。路徑 '',第1行,在C處ABCD.Background.Program.d__4.MoveNext()位置6:\項目\ ABCD \ ABCD.Background \的Program.cs:行25
線25是
DeserializedCustomer customer = JsonConvert.DeserializeObject<DeserializedCustomer>(email);
現在我妄圖調試器附加到這個webjob,因爲它是on demand
然後我就複製了網站工作職能的私有函數在我的控制器檢查,如果反序列化在我的工作web應用程序。我在本地運行我的網絡應用程序,並且令人驚訝的是,它的工作原理是!。
什麼可能是問題Newtonsoft.Json在asp.net mvc應用程序中工作,但不是在azure中部署的按需webjob?
幫助
更新
添加記錄到webjob使用
Console.WriteLine($"SerializedEmail - {serializedEmail}");
生成的跟蹤
[08/28/2017 11:39:44 > 1a8d37: SYS INFO] Status changed to Initializing
[08/28/2017 11:39:44 > 1a8d37: SYS INFO] Job directory change detected: Job file 'ABCD.Backgr.exe' timestamp differs between source and working directories.
[08/28/2017 11:39:45 > 1a8d37: SYS INFO] Run script 'ABCD.Backgr.exe' with script host - 'WindowsScriptHost'
[08/28/2017 11:39:45 > 1a8d37: SYS INFO] Status changed to Running
[08/28/2017 11:39:45 > 1a8d37: INFO] SerializedEmail - {email}
[08/28/2017 11:39:45 > 1a8d37: ERR ]
[08/28/2017 11:39:45 > 1a8d37: ERR ] Unhandled Exception: System.AggregateException: One or more errors occurred. ---> Newtonsoft.Json.JsonReaderException: Invalid JavaScript property identifier character: }. Path '', line 1, position 6.
[08/28/2017 11:39:45 > 1a8d37: ERR ] at Newtonsoft.Json.JsonTextReader.ReadUnquotedPropertyReportIfDone(Char currentChar, Int32 initialPosition)
[08/28/2017 11:39:45 > 1a8d37: ERR ] at Newtonsoft.Json.JsonTextReader.ParseUnquotedProperty()
更新
爲什麼這個帖子沒有通過點播azure web工作正確接收?
更新
發送一個簡單的對象與Web客戶端天青webjob
new System.Collections.Specialized.NameValueCollection
{
{"email",JsonConvert.SerializeObject(new {Email = "[email protected]"}) }
}));
日誌顯示相同
[08/28/2017 11:39:45 > 1a8d37: INFO] SerializedEmail - {email}
它是Web客戶端或捻SCM?
更新
要接收電子郵件參數我這樣做,但我沒有收到我的webjob
string serializedEmail = Environment.GetEnvironmentVariable("WEBJOBS_COMMAND_ARGUMENTS");
if (string.IsNullOrWhiteSpace(serializedEmail))
{
serializedEmail = args[0];
}
不過我沒有收到由asp.net的MVC發送的serializedEmail。
請這減少到[MCVE。鑑於'DeserializeObject'失敗,所有後面的代碼都是不相關的。看起來你的JSON很可能沒有被正確地檢索 - 你應該在反序列化之前在你的方法中記錄下'email'的值。我懷疑這不是你所期望的。 –
@JonSkeet在webjob中記錄了電子郵件的價值,當然這不是我所期待的。問題是如何從webclient接收帖子的問題? –
不知道 - 但現在您可以縮小問題的範圍,而不是JSON反序列化。 –