Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to INSERT a log in a Log table when a sms is sent successfully.

C#
string uid = "xxxx";
string password = "xxxx";
string SenderId = "xxxx";
string message = "Confirm Order No " + OrderNo + ". This Order Confirmation has been sent to you for your Ref. Order No: " + PoRefNo + ".";
string phoneNos = CustomerContact;
               
HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://xxxx.com/Xxxsms/xxxsms.aspx?user=" + uid + "&password=" + password + "&msisdn=" + phoneNos + "&sid=" + SenderId + "&msg=" + message + "&fl=0&gwid=2");
               
HttpWebResponse myResp = (HttpWebResponse)myReq.GetResponse();
               System.IO.StreamReader respStreamReader = new System.IO.StreamReader(myResp.GetResponseStream());
               
string responseString = respStreamReader.ReadToEnd();            
respStreamReader.Close();
myResp.Close();

               if (responseString != "Failed#Invalid Mobile Numbers")
               {
                   B2B_Order_Master_SAP_BAL objOrderBAL = new B2B_Order_Master_SAP_BAL();
                   DataSet dsMessage = objOrderBAL.uspB2BCustomerPortal_InsertOrderSMSLog(hfCustomerId.Value.ToString(), CustomerContact, OrderNo, message, "Customer Care", "UploadOrder_CustCare");
               }


What I have tried:

I am checking the value in "string responseString = respStreamReader.ReadToEnd(); "

if (responseString != "Failed#Invalid Mobile Numbers")
{
//Insert Log
}

Now the problem is i only know this one output:"Failed#Invalid Mobile Numbers" which is generated when invalid number is sent to api.

I want to know what other responses will be given by the api in terms of sms failure.
Posted
Updated 18-Jul-16 2:42am

1 solution

First thing: Didn't their API share those strings? Their API must enlist the values of the errors that come from servers.

Secondly, I would write it a bit differently, like this,
C#
if (!responseString.Contains("Failed")) {
   // Success
} else {
   // Error handling
   var errorMessage = responseString.Split('#')[1]; 
   // Get the Invalid Mobile Number part

   // Save it to the database, show it to the user or whatever. 
}

I would still recommend reading their API guides and documentation to learn more errors and how they are returned.

Just my own opinion, I believe using error codes is a better way to guide the clients about the errors instead of sending the strings.
 
Share this answer
 
Comments
Abrar Kazi 19-Jul-16 1:18am    
Thanks :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900