Reputation: 13253
I am trying to make make a RingOut call with RingCentral using their RingCentral SDK. I am basically following their tutorial found here:
https://developers.ringcentral.com/guide/voice/quick-start/c-sharp
Other than the fact that I'm trying to do this in an MVC web app and not in a console app my code basically looks identical to theirs:
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);
}
yet for some reason when I run this code I get the following error when the execution gets to the Authorization line:
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'.
Does anyone have any advice with regards to this? The SDK version I'm using is 1.2.1:
https://www.nuget.org/packages/RingCentral.Net/1.2.1
Upvotes: 1
Views: 815
Reputation: 20366
The original app in the tutorial is a console app. Can you also reproduce the issue with a console app? Or is this a web app only issue? I saw you opened a RingCentral support case. I will reply you in that support case. Once we found the root case I will post update here.
Update: I've tried the sample code provided by Marko and I think I've found the root cause. The RingCentral app being used doesn't allow password flow while we tried to authorize by password. More information about this issue: https://forums.developers.ringcentral.com/questions/452/http-400-unauthorized-for-this-grant-type.html
Upvotes: 0