我在AWS中运行了一个REST服务,它返回一些信息。当我从我的应用程序中访问该服务时,一切都很好。当我在调度任务中使用完全相同的代码时,它不会。奇怪的是,除了在Visual Studio中遍历代码时,当在调用JsonConvert.DeserializeObject
的行上点击F10时,它不会越过执行它的行,但它与点击F5相同,没有任何错误、异常、提示。
我的代码是:
private void infoRetrieval_DownloadCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
string response = e.Result;
if (response != null)
{
try
{
CDateTime info = null;
CJsonDateTime r = JsonConvert.DeserializeObject<CJsonDateTime>(response);
info = new CDateTime(r);
if (info != null)
{
// Indicate that there is a new info
}
}
catch (Exception exc)
{
// The exception can't be handled in a meaningful way, so it's ignored.
}
}
}
}
对Web服务进行实际调用的代码如下所示,它也是我在应用程序和代理中作为OnInvoke方法的一部分使用的完全相同的代码:
infoRetrievalClient = new WebClient();
infoRetrievalClient.DownloadStringCompleted += new DownloadStringCompletedEventHandler(infoRetrieval_DownloadCompleted);
infoRetrievalClient.DownloadStringAsync(new Uri(<the URI to the webservice>));
请注意,我在应用程序和ScheduledTaskAgent中使用的代码完全相同。此外,我检查了一下,在这两种情况下检索到的字符串完全相同。这里的问题只是我无法解析JSON并使用数据。
对NotifyComplete的调用在OnInvoke中。
非常感谢您的帮助,因为我目前正处于困境。
伊万
我解决了这个问题,结果Igor的问题让我走上了正轨。我将NotifyComplete移到了web请求的回调中,现在一切都处理得很好。
谢谢伊戈尔。
伊万