Microsoft.Graph.ServiceException:代码:ExtensionError消息:操作:读取;例外:[任务已取消。]

时间:2018-07-19 08:41:28

标签: c#

我将以下示例用于Microsoft Graph Webhook https://github.com/microsoftgraph/aspnet-webhooks-rest-sample 到昨天为止一切正常,但是现在出现以下错误:

  

Microsoft.Graph.ServiceException:代码:ExtensionError消息:操作:读取;异常:[任务被取消。] Microsoft.Graph.HttpProvider.d__19.MoveNext()的内部错误---从上一个引发异常的位置开始的堆栈跟踪---在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Graph.BaseRequest.d__36.MoveNext()---从上次引发异常的位置开始的堆栈跟踪---在System.Runtime。 Microsoft.Graph.BaseRequest.d__32`1.MoveNext()处System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task任务)处的ExceptionServices.ExceptionDispatchInfo.Throw()-从上次引发异常的位置开始的堆栈跟踪- -在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(任务任务)在Microsoft.Graph.SubscriptionReque st.d__6.MoveNext()-从上一个引发异常的位置开始的堆栈跟踪--在System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task任务)的System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()在 - - - - - - - - - - - - - - - - - - - - - - - - - -

任何人都遇到类似的问题,需要使用Microsoft.Graph API来获取电子邮件通知或创建订阅 甚至我在 https://apps.dev.microsoft.com

并在“ Microsoft Graph权限”部分中提供以下权限, 委托的权限:
邮件。阅读
用户。阅读

应用程序权限:
Mail.Read(仅限管理员)
User.Read.All(仅限管理员)

甚至现在在创建订阅时,我也遇到同样的错误:

在创建订阅令牌时,会创建一个Webhook并监听请求,但是当我将响应返回给Microsoft Graph时,出现以下错误:

  

Microsoft.Graph.ServiceException:代码:ExtensionError消息:操作:创建;例外:[任务已取消。]

     

令牌:YTQyYTY5YzctYjg0Ny00Zjg0LWFiMWItMTQ1OGRkYmY2M2Q2

我正在使用以下代码创建订阅: //已向Webhook订阅注册的notificationUrl端点。

[HttpPost]
public async Task<ActionResult> Listen()
{

    // Validate the new subscription by sending the token back to Microsoft Graph.
    // This response is required for each subscription.
    if (Request.QueryString["validationToken"] != null)
    {
        var token = Request.QueryString["validationToken"];
        return Content(token, "plain/text");
    }

    // Parse the received notifications.
    else
    {
        try
        {
            var notifications = new Dictionary<string, Notification>();
            using (var inputStream = new StreamReader(Request.InputStream))
            {
                var jsonObject = JObject.Parse(inputStream.ReadToEnd());
                if (jsonObject != null)
                {

                    // Notifications are sent in a 'value' array. The array might contain multiple notifications for events that are
                    // registered for the same notification endpoint, and that occur within a short timespan.
                    JArray value = JArray.Parse(jsonObject["value"].ToString());
                    foreach (var notification in value)
                    {
                        var current = JsonConvert.DeserializeObject<Notification>(notification.ToString());

                        // Check client state to verify the message is from Microsoft Graph.
                        var subscription = SubscriptionCache.GetSubscriptionCache().GetSubscriptionInfo(current.SubscriptionId);

                        // This sample only works with subscriptions that are still cached.
                        if (subscription != null)
                        {
                            if (current.ClientState == subscription.ClientState)
                            {
                                // Just keep the latest notification for each resource.
                                // No point pulling data more than once.
                                notifications[current.Resource] = current;
                            }
                        }
                    }

                    if (notifications.Count > 0)
                    {

                        // Query for the changed messages.
                        await GetChangedMessagesAsync(notifications.Values);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            // TODO: Handle the exception.
            // Still return a 202 so the service doesn't resend the notification.
        }
        return new HttpStatusCodeResult(202);
    }
}

0 个答案:

没有答案
相关问题