Skip to main content

Hello Everyone, this is the code snippet. This is working on the previous version of my site, DNN 5.6, but since I upgraded to DNN 9, this method fails to execute and takes an infinite amount of time to load.
 

                RestClient restClient = new RestClient(matchMaker.ClientRingCentralId, matchMaker.ClientSecret, RestClient.ProductionServer);

 

                await restClient.Authorize(matchMaker.JwtAuthToken);


The credentials are the same in both versions.

I am not an expert in DNN so I cannot say what could be wrong. But are the credentials created for your production account? Can you test them with some other programming languages?


I had tried the request through Postman, and it is working fine as expected. Maybe the only issue is dnn9. Can you suggest which version I should use? Or is there any other issue?


I had tried the request through Postman, and it is working fine as expected. Maybe the only issue is dnn9. Can you suggest which version I should use? Or is there any other issue?

I Google and found these info which may help you to investigate

 

Explanation:

  • async Task<IHttpActionResult>: The async keyword indicates that the method contains await expressions. The Task<IHttpActionResult> signifies that the method will return an IHttpActionResult when the asynchronous operation completes.
  • await httpClient.GetStringAsync(...): The await operator suspends the execution of GetSomeDataAsync until the asynchronous GetStringAsync call finishes. During this time, the thread is free to handle other requests, preventing the server from being blocked. 

Important Considerations:

  • DNN Platform limitations: While async and await are powerful, note that in some older versions of DNN Platform, the main response pipeline might not fully support the async/await pattern. You may need to investigate workarounds or upgrades for complete compatibility.
  • Web API vs. UI: This example focuses on Web API controllers. For UI elements (e.g., in a module's code-behind), you would apply async and await to event handlers, like button clicks, to keep the UI responsive while asynchronous tasks are running.
  • Error Handling: Include appropriate error handling (e.g., try-catch) to manage potential issues during the asynchronous call. 

By using async and await in your DNN 9 API calls, you can improve the performance and responsiveness of your modules and web applications, especially when dealing with I/O-bound operations

 

Is this line inside an async function?
 await restClient.Authorize(matchMaker.JwtAuthToken);


        public async Task<bool> send_sms(MatchmakersRingCentralCredenitalsDto matchMaker, string RECIPIENT, string content, RingCentral.Attachmentm] listAttachment, int clientId)
        {
            bool flag = false;
            try
            {
                 ServicePointManager.SecurityProtocol = (SecurityProtocolType)768 | (SecurityProtocolType)3072;
                 RestClient restClient = new RestClient(matchMaker.ClientRingCentralId, matchMaker.ClientSecret, RestClient.ProductionServer);

                 await restClient.Authorize(matchMaker.JwtAuthToken);

                string resPhoneNumber = await detect_phone_number_feature(restClient);
                if (!string.IsNullOrEmpty(resPhoneNumber) && !string.IsNullOrEmpty(content) && !string.IsNullOrEmpty(countryCode))
                {
                    var parameters = new CreateMMSMessage();
                    parameters.from = new MessageStoreCallerInfoRequest { phoneNumber = resPhoneNumber };
                    RECIPIENT = countryCode + RECIPIENT;
                    parameters.to = new MessageStoreCallerInfoRequestP] { new MessageStoreCallerInfoRequest { phoneNumber = RECIPIENT } };
                    parameters.text = content;
                    parameters.attachments = listAttachment;

                    var resp = await restClient.Restapi().Account().Extension().Mms().Post(parameters);

                    if (resp != null)
                    {
                        flag = true;
                        lblMsgSendResult.Visible = true;
                        lblMsgSendResult.Text = "Message sent successfully.";
                        lblMsgSendResult.CssClass = "success";
                        GetMessageSyncResponse requestModelSmsObject = new GetMessageSyncResponse();
                        requestModelSmsObject.records = GetSMSObject(resp);
                        if ((new MassMessagesController()).SaveRingCentralSmsResponse(requestModelSmsObject, matchMaker.MatchMakerID))
                        {
                            await SaveAttachments(requestModelSmsObject, restClient, matchMaker.MatchMakerID);
                            (new MassMessagesController()).UpdateRingCentralClientId(Convert.ToString(clientId), Convert.ToString(requestModelSmsObject.recordsÂ0].id));

                        }
                    }
                }
                else
                {
                    lblMsgSendResult.Visible = true;
                    lblMsgSendResult.Text = "The requested feature is not available for this phone number.Please contact Administrator.";
                    lblMsgSendResult.CssClass = "failure";
                    flag = false;
                }
            }
            catch (Exception e)
            {
                if (!string.IsNullOrWhiteSpace(e.Message) && e.Message.Contains("Invalid resource owner credentials"))
                {
                    lblMsgSendResult.Visible = true;
                    lblMsgSendResult.Text = "Invalid RingCentral User Credentials .Please try again later.";
                    lblMsgSendResult.CssClass = "failure";
                }
                else
                {
                    lblMsgSendResult.Visible = true;
                    lblMsgSendResult.Text = "There is some problem in sending message.Please try again later.";
                    lblMsgSendResult.CssClass = "failure";
                }
                Exceptions.LogException(e);
            }
            return flag;
        }



this is the whole piece of code. The same code was working on DNN 5.6 but not on DNN 9. I am using the same DLL in both versions. I have tried different versions but still facing the same issue.


Reply