How to Build a Real-time Voting App with .NET and C#
You can easily build a live real-time voting app in the browser with C# and .NET, enabling users to vote and see results, updated in real time.
Have you ever thought of implementing the C# PubNub API with ASP.NET MCV4? Whether you have or not, in this tutorial, we’ll walk you through how to build a web-based real-time voting application. This will enable users to vote, and the results will be automatically tallied and displayed. We’ll be using the PubNub C# SDK for both
DetailedHistory to demo the voting web app.
In a real-time application, we expect the question and the choice of answers/responses come from a database. To keep things simple, I’ll hard code the questions and answer options as a xml string in
GetActivePollQuestion() method of
SampleData class. In real-time, you can return dynamic data as xml string.
Schemas for a Real-time Voting App
Two schemas PollQuestion.xsd and PollUserAnswer.xsd were created.
PollQuestion.cs and PollUserAnswer.cs class files were generated using xsd.exe tool using the following commands:
Take a look at their schemas below:
Publishing Messages over WebSockets for Real-time Voting
Once the poll answers are submitted to PubNub, the success status of message publish will be displayed as view to the web user as below: