首页 > 解决方案 > Microsoft.Graph.ServiceException:代码:ExtensionError 消息:操作:读取;例外:[任务被取消。]

问题描述

我正在为 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(Task task) 在 Microsoft.Graph.BaseRequest.d__36.MoveNext() --- 在 System.Runtime 中从先前抛出异常的位置结束堆栈跟踪。 ExceptionServices.ExceptionDispatchInfo.Throw() 在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) 在 Microsoft.Graph.BaseRequest.d__32`1。

任何人在使用 Microsoft.Graph API 获取电子邮件通知或创建订阅时都面临类似的问题,即使我在 https://apps.dev.microsoft.com中重新配置了应用程序

并在“Microsoft Graph 权限”部分的委派权限中授予以下权限:
Mail.Read
User.Read

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

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

在创建订阅令牌时创建并 webhook 侦听请求,但是当我将响应返回给 Microsoft Graph 时,我收到以下错误:

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

代币:YTQyYTY5YzctYjg0Ny00Zjg0LWFiMWItMTQ1OGRkYmY2M2Q2

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

[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);
    }
}

标签: c#

解决方案


推荐阅读