ringcentral / ringcentral-csharp-client

RingCentral C# Client
https://developer.ringcentral.com
19 stars 19 forks source link

SMS is being sent 2 times using c# sdk #2

Closed shashank0764 closed 7 years ago

shashank0764 commented 8 years ago

Hello team,

, i am sending only one but receiving 2 sms messages after an interval of around 5-7 minutes containing the same text. i have verified my code and it executes only time and after that i quit my application. I am using c# SDK. this was sending only one sms some days back but i am not sure why it is sending multiple sms now. please check ////ring central code starts
var ringCentral = new RingCentral.XDK.ApiClient(appkey, appsecret,defaultendpoint);

                //Login
                ringCentral.Login(userphonenumber, password);

                //Sending SMS
                ringCentral.SMS.Send(fromnumber, phonenumber, msgcontent);

                szResponseString = ringCentral.res;

                var obj = JObject.Parse(szResponseString);
                string statusresp = (string)obj.SelectToken(ConfigurationManager.AppSettings["messagestatuskey"]);
                string messageid = (string)obj.SelectToken(ConfigurationManager.AppSettings["messageidkey"]);

Please find the dev community link below.

https://devcommunity.ringcentral.com/ringcentraldev/topics/sms-is-sending-2-times-through-api

tylerlong commented 8 years ago

I don't think you are using the official SDK. Because your code seems very strange to me:

var ringCentral = new RingCentral.XDK.ApiClient(appkey, appsecret,defaultendpoint);

Please read the readme file for the sample code: https://github.com/ringcentral/ringcentral-csharp-client

This project is currently in beta, we have another project which is stable: https://github.com/ringcentral/ringcentral-csharp

You code uses neither of the two above, so we cannot provide any more comments.

shashank0764 commented 8 years ago

Hello Tyler, Thanks for the information i am now using the new SDK which you mentioned in the second link but it is giving me an error while login, please check the attachment.
smsloginerror

shashank0764 commented 8 years ago

Hello Tyler,

Below is the code i use

         sdk = new SDK(appKey, appSecret, SDK.Server.Sandbox, "C Sharp Test Suite", "1.0.0");
        // mock test only, don't contact remote server
        sdk.Platform._client = new HttpClient(new RingCentral.Test.MockHttpClient()) { BaseAddress = new Uri(SDK.SandboxServerUrl) };
        sdk.Platform.Login(phoneNumber, "", password, true);

        var from = senderPhoneNumber;
        var to = recipientPhoneNumber;
        var text = "Test SMS message";
        var jsonData = "{\"to\": [{\"phoneNumber\": \"" + to + "\"}]," +
                       "\"from\": {\"phoneNumber\": \"" + from + "\"}," +
                      "\"text\": \"" + text + "\" }";
        Request request = new Request(SmsEndPoint, jsonData);
        ApiResponse result = sdk.Platform.Post(request);

        JToken token = JObject.Parse(result.Body);
        var messageStatus = (string)token.SelectToken("messageStatus");

Thanks, Shashank.

tylerlong commented 8 years ago

I read your code and you are running sample code from unit tests. These are for mock testing only, not for real world usage.

Please read the doc for sample code: http://ringcentral-csharp.readthedocs.io/en/latest/

shashank0764 commented 8 years ago

Hello ,

i used the new code now as mentioned in the above link still it breaks in the same place as the ring central dll is pointing to platform.cs

var sdk = new SDK(appKey, appSecret, SDK.SandboxServerUrl, "Application Name", "Application Version");

        // Password Grant Authorization
        var response = sdk.Platform.Login(phoneNumber, "", password, true);

        var jsonString = "{ \"text\":  \"hello sms!\", \"from\": { \"phoneNumber\": \"15188315172\" }, \"to\": [{ \"phoneNumber\": \"19295755445\" }] }";
        var request = new Request("/restapi/v1.0/account/~/extension/~/sms", jsonString);
        var response1 = sdk.Platform.Post(request);
shashank0764 commented 8 years ago

Hello ,

once i commented the below code in the platform.cs inside the SDK then only it worked. image

shashank0764 commented 8 years ago

Hello Tyler,

Please let me know if commenting the above line is ok as this had apparently made the SMS work. Can i close the issue?

Thanks, Shashank.

tylerlong commented 8 years ago

Hi @shashank0764 ,

First of all, this is not the right place for your question. You are talking about https://github.com/ringcentral/ringcentral-csharp which is not the current repository.

Why do you need to change the source code of the SDK? How did you install it? The recommended way is to install it via NuGet. As shown in the readme file of https://github.com/ringcentral/ringcentral-csharp

Install-Package RingCentralSDK

Last but not least. could you please post the full stack trace of the exception? And from your first screenshot, there was a NullReferenceExcepotion, could you please tell me which object is null?