SignalR: 1st Project

So I wanted to learn more about SignalR so I went over to GitHib and checked out their getting started page.  The page makes some assumptions that a new .NET developer might run into so I thought I would show how I got it working.

Step #1: Open Visual Studio 2012 and File->NewProject  and select ASP.NET Empty Web Application:

image I

Note that I made the solution name different than the name of the project because I will be added another project to this solution.

Step #2: Add a new console application to the solution:

image

Your solution should now look like this:

image

Step #3: Go to the Server project and open the NuGet Package Manager Console:

image

In the Package Manager Console Window, type

Install-Package Microsoft.AspNet.SignalR

Make sure that the Default Project is the Server project you created

image

after you hit enter, NuGet will do a bunch of stuff for you (adding libraries, resolving dependencies, etc…) and open the readme.txt file.  You can close that window.

Step #4: Add a class to your server project  called MyConnection (you are using Shift+Alt+C aren’t you?):

image

Step #5: Type (or copy) the code into your MyConnection class.  Note that you are inheriting from the PersistentConnection class and you will have to resolve (CTRL+.) both that class and the Task class.

image

Your class should look like this:

image

Step #6: Add a Global.asax file to your server project

image

Then type(or copy) the code into your Application_Start event handler:

image

Note that you will have to resolve the RouteTable class (CTRL+.).

The server project is now ready to go.  Make sure the server project is the startup project and run it.  IE will launch and you will get a web page like this:

image

Make a note of the address.  You can then stop the project from running.

Step #7: Go to the Client project and open the NuGet Package Manager Console and install the SignalR Client package.  Important, make sure that the default project is pointed to the client project

image

Step #8 Go to the Program.Main method and type (or copy) the code in.  Note that you will have to resolve the Connection class

image

Note that the address for the connection will be different for your machine.  Match that connection address back to the uri that IE showed you when you ran the server project.

Step #9: Open up the Configuration of the solution file and change the solution to have multiple startup projects.  Make sure you change the order so the client starts AFTER the server

image

Step #10 Run the solution and make the console window have focus.  Type in something and see the server push that message back out to you

image

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: