我有一个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反序列化。 –