Click here to Skip to main content
15,906,816 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
hi,
to do that i made a web service to send push (by referencing PushSharp library). I request web service through my web application. i retrieve list of device token from database(using web application) send to web service using for loop to send push. and get result/exception for each one. This process is very slow and take long long time to send notification. If anybody suggest me to what should i do i will be grateful to you.

C#
<pre lang="c#"><pre lang="c#">
C#
public ActionResult SendNow(int certificateInfoId, string message, string certificate, int badgeNo, int pushtype, string password, string countryJsonString)
        {
            if (IsPushParameterValid(certificateInfoId, message, certificate, badgeNo, pushtype, password, countryJsonString))
            {
                var countryObject = new JavaScriptSerializer().Deserialize<Country>(countryJsonString);
                var errorList = new List<ErrorList>();
                byte[] certificatePath = System.IO.File.ReadAllBytes(HttpContext.Server.MapPath("~/Content/certificate/" + certificate));
                foreach (var aDeviceToken in countryObject.DeviceTokens)
                {
                    try
                    {
                        var serviceClient = new PushServiceSoapClient();
                        string serviceResult = serviceClient.SendPushNotification(message, badgeNo, pushtype, aDeviceToken.Token, certificatePath, password);

                        if (serviceResult != "Sent Notification")
                        {
                            var delimiters = new[] { ' ' };
                            string[] errorResult = serviceResult.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);
                            string errorMessage = ConvertErrorCodeToErrorMessage(errorResult[0]);
                            var error = new ErrorList
                            {
                                CountryName = countryObject.CountryName,
                                ErrorTime = DateTime.Now,
                                ErrorMessage = errorMessage,
                                Token = aDeviceToken.Token
                            };
                            errorList.Add(error);
                        }
                    }
                    catch (Exception ex)
                    {
                        var error = new ErrorList
                         {
                             CountryName = countryObject.CountryName,
                             ErrorTime = DateTime.Now,
                             ErrorMessage = ex.Message,
                             Token = aDeviceToken.Token
                         };
                        errorList.Add(error);
                    }
                }
                if (errorList.Count != 0)
                {
                    ViewBag.Message = "Push Notification does not send to country... ";
                    return PartialView("_SendAllError", errorList.ToList());
                }
                errorList.Clear();
            }
            return View();
        }
Posted
Updated 8-Aug-15 17:23pm
v4
Comments
Ben J. Boyle 30-Jul-15 11:45am    
Which platform are you pushing to? I think both Google and Apple support some kind of grouping mechanism that would allow you to send a single message to the entire group (or all application users) rather than needing to send to each individual client.

I'm not familiar with PushSharp but it would likely support that scenario too.
suzand 1-Aug-15 23:39pm    
.net platform
virusstorm 30-Jul-15 12:54pm    
If you are using .NET platform, take a look at SignalR
http://www.asp.net/signalr
suzand 1-Aug-15 23:39pm    
I'm using .Net platform
suzand 2-Aug-15 0:39am    
Though I don't know about signalr but i will learn myself. would you explain the entire mechanism to send push using signalr.
NB.:my existing mechanism is "web application retrieve list of device token by app_id and country then using loop each device token (with push message) send to web service (made using pushSharp library). Actually web service send push to APNS(Apple Push Notification Service)".

1 solution

It doesn't look like Apple themselves support grouping messages, only one message per device.

You could look at something like Urban Airship that allows you to tag devices with identifiers, in your case countries, and then send a message by tag. Urban Airship would then handle the breakout and send the individual messages so your server is not bogged down with that load.
 
Share this answer
 
Comments
suzand 9-Aug-15 0:39am    
I just need to know mechanism. I would like to develop myself.

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