Background
There are many tutorials for creating chat applications in MVC using SignalR (Here). We can use this same concept to allow SharePoint app parts to communicate with each other. SharePointers usually encounter this problem where they want their app parts to convey some information to each other. Since these app parts are in two different Iframes, they don't have many options for communicating with each other in real time. We can use SignalR to solve this problem.
After reading this article you will be able to create a SharePoint app part that displays the survey results chart that is updated at the instant someone submits a vote in the other app part. So one app part acts as the sender and one receiver, unlike a chat app where both the clients act as senders and receivers.
Here is the procedure
- To start, create a provider-hosted (MVC) SharePoint app using Visual Studio 2013.
- The MVC app must have two views: One view that allows the user to vote on certain Survey Questions and another view that shows the current survey result in the form of a Pie chart. (I have used SharePoint lists to store questions and answers and the corresponding vote count.)
- Once you are done with the two views and your app is up and running, install the Nuget package ASP.NET SignalR in the MVC app from the Package Manager or from the command line.

- Add SignalR Hub class

- Code for sender (view that allows user to vote on certain Survey Questions)

- Code for receiver (view that shows the current survey result in the form of a pie chart)

- Add a reference to the following script files in both the sender and the receiver view:

- Combined API for all SignalR JavaScript operations
InitReceiver: contains the receiver's code. Called in the doc.ready event handler of the receiver.
InitSender: contains the event handler for the submit vote button.
StartConnection(callback): starts a connection and accepts a callback function that is called in the "done" success handler of the start method. Here is how the sender and receiver code looks like now.


- Run the app
Now you can add these two views as App parts on your SharePoint tenant page and you will have two app parts that are communicating with each other using SignalR. To understand how to add MVC views as app parts in SharePoint check out my blog.


farooq smdPosted Sep 8, 2016, 9:40 AM
Nice one
SriramPosted Jul 3, 2015, 7:39 AM
Super............
ShwetaPosted May 6, 2015, 1:48 AM
Thank you everyone.
Karthik Muthu KaruppanPosted May 4, 2015, 2:25 PM
nice
Tom MohanPosted May 2, 2015, 11:28 AM
Great start... Keep sharing :)
NitinPosted May 1, 2015, 3:34 AM
good one
Santhakumar MunuswamyPosted Apr 30, 2015, 12:35 AM
Thanks for nice article
Santhakumar MunuswamyPosted Apr 30, 2015, 12:35 AM
Welcome
Santhakumar MunuswamyPosted Apr 30, 2015, 12:35 AM
Good Start
RakeshPosted Apr 29, 2015, 9:05 PM
Good start...Keep it up