question

station 1 lurie avatar image
station 1 lurie asked Tyler Liu commented

Authorize takes forever with password flow

Hey


I use nuget RingCentral.Net to connect to API and Password flow with sandbox Server only platform


When I connect with console application with the following code I succeed (get token and get call logs)


var rc = new RestClient(Config.Instance.clientId, Config.Instance.clientSecret, Config.Instance.server); 
var token = rc.Authorize(Config.Instance.username, Config.Instance.extension, Config.Instance.password).Result; 


When I try to connect to api with an application (ASP.NET MVC) that is on IIS the authorize takes forever, without exception

getting started
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Tyler Liu avatar image
Tyler Liu answered
Hi, it might be deadlock issue.

And it is a common C# async programming issue:  https://medium.com/rubrikkgroup/understanding-async-avoiding-deadlocks-e41f8f2c6f5d

In short, do not mixed async code and sync code.  If your app is async overall, you should not use .Result.
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

station 1 lurie avatar image
station 1 lurie answered Tyler Liu commented
Thanks, call log work perfect but when i want to send sms like

static async Task Main(string[] args)
{
using (var rc = await Login()) { await SendSms(rc); } }
private static async Task<RestClient> Login()
{
    var rc = new RestClient("***", "*********", "https://platform.devtest.ringcentral.com/");
    await rc.Authorize("+*****", "101", "*****");
    return rc;
} public static async Task SendSms(RestClient rc)
{
    var sms = new CreateSMSMessage()
    {
        @from = new MessageStoreCallerInfoRequest() { phoneNumber = "+****" },
        to = new[] { new MessageStoreCallerInfoRequest() { phoneNumber = "+****" }, },
        text = "test yaacov"
    };
     var resTask = await rc.Restapi().Account().Extension("101").Sms().Post(sms);
}
The Authorize return token but post sms get exception 
System.ObjectDisposedException: 'Cannot access a disposed object.
Object name: 'System.Net.Http.StringContent'.'
When i run same details with Api reference "try it out" button it work fine
3 comments
1 |1500 characters needed characters left characters exceeded

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

"101" is extension number, extension ID is expected when invoking the API.
0 Likes 0 ·
Thank you very much, now it works great :)
I wasted a lot of time on this :(
0 Likes 0 ·
Good to known that it works. Have a nice day!
0 Likes 0 ·

Developer sandbox tools

Using the RingCentral Phone for Desktop, you can dial or receive test calls, send and receive test SMS or Fax messages in your sandbox environment.

Download RingCentral Phone for Desktop:

Tip: switch to the "sandbox mode" before logging in the app:

  • On MacOS: press "fn + command + f2" keys
  • On Windows: press "Ctrl + F2" keys