首页 > 解决方案 > 尝试通过 RingCentral SDK 进行 RingOut 调用时,为什么会出现“无法访问已处置的对象”错误?

问题描述

我正在尝试使用他们的 RingCentral SDK 与 RingCentral 进行 RingOut 通话。我基本上遵循他们在此处找到的教程:

https://developers.ringcentral.com/guide/voice/quick-start/c-sharp

除了我试图在 MVC Web 应用程序中而不是在控制台应用程序中执行此操作之外,我的代码基本上与他们的代码相同:

    public async Task<JsonResult> Call(string number)
    {
        var rc = new RestClient(RingCentralCredentials.ClientId, RingCentralCredentials.ClientSecret, false);
        var tokenInfo = await rc.Authorize(RingCentralCredentials.Username, RingCentralCredentials.Extension, RingCentralCredentials.Password);
        // The above line throws the exception.
        var parameters = new MakeRingOutRequest();
        parameters.from = new MakeRingOutCallerInfoRequestFrom { phoneNumber = RingCentralCredentials.Username };
        parameters.to = new MakeRingOutCallerInfoRequestTo { phoneNumber = number };
        parameters.playPrompt = false;
        var resp = await rc.Restapi().Account().Extension().RingOut().Post(parameters);
        return Json(resp.status, JsonRequestBehavior.AllowGet);
    }

但是由于某种原因,当我运行此代码时,当执行到达授权行时出现以下错误:

Cannot access a disposed object.
Object name: 'System.Net.Http.FormUrlEncodedContent'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Http.FormUrlEncodedContent'.

有人对此有什么建议吗?我使用的 SDK 版本是 1.2.1:

https://www.nuget.org/packages/RingCentral.Net/1.2.1

标签: c#ringcentralringout

解决方案


本教程中的原始应用程序是一个控制台应用程序。您还可以使用控制台应用程序重现该问题吗?或者这是一个网络应用程序唯一的问题?我看到你打开了一个 RingCentral 支持案例。我会在那个支持案例中回复你。一旦我们找到了根本案例,我将在此处发布更新。

更新:我已经尝试了 Marko 提供的示例代码,我想我已经找到了根本原因。当我们尝试通过密码进行授权时,正在使用的 RingCentral 应用程序不允许密码流。有关此问题的更多信息:https ://forums.developers.ringcentral.com/questions/452/http-400-unauthorized-for-this-grant-type.html


推荐阅读