Push Notifications to all platforms using a web Api (c# and .Net)

UPDATE 07/01/2015

This blog post was written a long time back. At the time, I could not find a free platform for sending push notifications to multiple mobile platforms. Thus, I forked PushSharp and started wrapping it in a web app. Since then, many similar services have come light. Microsoft Azure does currently provide a similar platform and the cost is quite reasonable. The content here still valid if you are interested in building your own notification server to save on cost. For more info about Azure Push Notifications, see this on MSDN

This post shows how to use PushSharp.Web to send push notifications from anywhere using a Web Api wrapper around lovely PushSharp.

PushSharp library

Recently, I was tasked to implement a Push Notification teir on our Server end when certain conditions are met.
I needed to send Push Notifications to iOS, Android, and Windows Phones.

After doing some investigation, I found that PushSharp was the best candidate available to help me send to multiple platforms
in one languages.

The Problem was my sever application was using .NET 3.5 CF, and we cannot update just yet. We still support lots of apps that are operating on Windows Mobile 6, and that was the catch. PushSharp needs .Net either 4.0 or 4.5 to work, that is because it uses many of .NET 4.0 libraries such as TPL (Task Parallel Library). I thought of few other solutions like making the PushSharp a windows phone and getting my app to talk to it via some interop channels, but I thought that was going back.

Thus, I ended up creating a new WebApi that acts as a wrapper around PushSharp. That way, the PushNotifications can be separate and I can use the same WebApi to build more functionality that is not available for me in .NET 3.5. Having said that, This WebApi can be used with any other platform or language. The fact that it exposes the sending of Push Notifications as a webApi service makes it available for any platform or language that you are using.
You could use it from PHP, Ruby, etc.

The whole source code is available under GitHub, have a look and feel free to fork and do whatever you like with it.

Few things to note:

1. Apple Certificate settings need to be set in the Web.Config before hand. (if you plan to send to iOS devices)
2. Google Api key needs to be set in the Web.Config (if you intend to send to Android Devices)
3. Same with other platforms like Windows Phone, and Windows Store settings.
4. The WebApi app makes use of NLog, so the config file is separate from the Web.Config and you could update it to your needs.

I would love to hear your thoughts about how great or terrible job I have done. If you like it, please do get in touch by leaving a comment down this page.


10 Replies to “Push Notifications to all platforms using a web Api (c# and .Net)”

  1. Hello how r u ?

    Thank u brother

    Im using asp.net 3.5

    How I can use this library in my project ? Such as what I should have to install it ? Because I did not find binarry file to referencing it inside my project

    please help me


    1. Hi Mohamed,

      You cannot reference PushSharp from .Net 3.5,
      What you can do is to create a webApi that works as a wrapper around PushSharp. It is like you are creating your own Push notification service, then your code (.Net 3.5) can invoke this newly created WebApi

      Hope that makes sense and helps you 🙂

    1. Hi @Vasanth,

      PushSharp.Web is just a wrapper around PushSharp. You could fork the repo, make your own changes and deploy it as a web app to Azure or any other server. All you need (after deployment) is to set up the certificates and keys (Apple APNS certificate, and Google GSM key). Full reference on how to do this can be found here: https://github.com/Redth/PushSharp/wiki

  2. Hello i m using 4.5 .net and push sharp is not working . i read somewhere that pushsharp is only working in 4.0 .net . so is it possible to use in 4.5 and if it is yes then how ??

    1. Thanks Mohammad, and sorry I was on holiday and just saw ur question.
      I hope your issue have been resolved by now and to be honest I am not sure about compatibility of PushSharp and .Net 4.5

    1. In my case, I used PushSharp which s a .net library, hosted that in a web application, then my code would call this web app to send notification. Have a look at PushSharp.web and all u need is to call it using HTTP calls

Leave a Reply

Your email address will not be published. Required fields are marked *