Introduction

SignalR, Microsoft’s latest addition to the web development technology stack, is a framework that facilitates the creation of amazing real-time applications, such as online collaboration tools, multiuser games, and live information services, whose development has traditionally been quite complex.

This book provides a complete walkthrough of SignalR development from scratch, but it will also deal with more advanced topics. The idea is that after reading it you will be familiar with the possibilities of this framework and able to apply it successfully in practice in the creation of real time systems of any size. It can also be used as a reference manual because, although not exhaustively, it includes most features of practical application in the development of SignalR systems, and it provides the bases for fully mastering them.

Who should read this book

The aim of this book is to help developers understand, know, and program SignalR-based components or applications. It can be of special interest to developers who need to make use of real-time immediacy in existing applications or who want to create new systems based on this paradigm.

Developers specializing in the back end will learn to implement real-time services that can be consumed from any client and to address scenarios such as those requiring scalability or quality improvement via unit tests. Those who are more oriented to the front end will see how they can consume real-time services and add spectacular features to their creations on the client side. Web developers, especially, will find a really simple way to break the limitations characteristic of the HTTP-based world, thanks to the use of push and the asynchrony of these solutions.

Assumptions

In this book, we will assume that the reader has a good knowledge of C# and programming within the .NET environment in general. Also, because SignalR itself and many of the examples and contents are focused on the web world, it is necessary to know the protocols on which it rests, as well as having a certain knowledge of the basic languages of these environments, such as HTML and, in particular, JavaScript.

Although not strictly necessary, the reader might benefit from some prior knowledge about development with jQuery, Windows Phone 8, or WinRT for the chapters that develop examples and contents related to them. Familiarity with techniques such as unit testing, mocking, and dependency injection to get the most out of the final chapters could also prove helpful.

Who should not read this book

Readers who do not know the .NET platform and C# will not be able to benefit from this book. If you do not have prior knowledge of JavaScript, it will be difficult to follow the book’s explanations.

Organization of this book

This book is structured into nine chapters, throughout which we will go over different aspects of the development of real-time multiuser systems with SignalR, starting from scratch and all the way up to the implementation of advanced features of this framework.

Chapter 1 and Chapter 2 are purely introductory, and they will help you understand the technological context and the foundations on which this new framework rests.

In Chapter 3 we will present SignalR at a high level, showing its position in the Microsoft web development technology stack and other related concepts such as OWIN and Katana.

From this point, we will begin to look in detail at how to develop applications by using SignalR. We will dedicate Chapter 4 and Chapter 5 to study development from different levels of abstraction, using persistent connections and hubs. In Chapter 6 we will study how to integrate these components with other technologies within the same application, and in Chapter 7 we will see how to implement multiplatform clients.

Chapter 8 will show different deployment scenarios and the scaling solutions offered by SignalR. In Chapter 9 we will find miscellanea where we will deal with more advanced aspects, such as security, extensibility, testing, and others.

Finding your best starting point in this book

Although this book is organized in such a way that it can be read from beginning to end following a path of increasing depth in the contents addressed, it can also be used as a reference by directly looking up specific chapters, depending on the level of knowledge the reader starts with and their individual needs.

Thus, for developers who are approaching SignalR for the first time, the recommendation would be to read the book from beginning to end, in the order that the chapters have been written. However, for those who are acquainted with SignalR and have already developed with it in any of its versions, it will suffice to take a quick look at the first three chapters and then to pay closer attention to the ones dedicated to development with persistent connections or hubs to find out aspects they did not know about or changes from previous versions. From there, it would be possible to go directly to resolving doubts in specific areas, such as the scalability features of the framework, implementing authorization mechanisms, or the procedure for performing unit tests on hubs.

In any case, regardless of the chapter or section, it is a good idea to download and install the related example projects, which will allow practicing and consolidating the concepts addressed.

Conventions and features in this book

This book presents information using the following conventions designed to make the information readable and easy to follow:

  • Boxed elements with labels such as “Note” provide additional information or alternative methods for successfully completing a task.

  • Text that you type (apart from code blocks) appears in bold.

  • A plus sign (+) between two key names means that you must press those keys at the same time. For example, “Press Alt+Tab” means that you have to hold down the Alt key while you press the Tab key.

  • A vertical bar between two or more menu items (for example, “File | Close”) means that you should select the first menu or menu item, then the next one, and so on.

System requirements

To be able to adequately follow the examples shown in this book and practice with them, it is necessary to have, at least, the following hardware and software items:

  • A computer equipped with a processor whose speed is at least 1.6 GHz (2 GHz recommended).

  • 2 GB RAM (4 GB is advisable).

  • A video card compatible with DirectX 9, capable of resolutions above 1024x768.

  • The operating systems Windows 7 SP1, Windows 8, Windows 8.1, or Windows Server editions above 2008 R2 SP1.

  • Internet Explorer 10.

  • Visual Studio 2012 or above, in any of its editions. It is possible to use Express versions in most cases.

  • An Internet connection.

Some examples might require that you have a system account with administrator permissions or that you install complements such as the Windows Phone SDK. In some chapters, external resources are also used, such as Windows Azure services.

Code samples

Throughout this book you can find examples, and even complete projects, to illustrate the concepts dealt with. The majority of these, as well as other additional examples, can be downloaded from the following address:

http://aka.ms/SignalRProg/files

Follow the instructions to download the SignalRProgramming_codesamples.zip file.

Note

In addition to the code samples, your system should have Visual Studio 2012 or 2013 installed.

Notes on the version

This book has been written using version 2.0.0 of SignalR, so throughout it you will find various references to that specific version.

However, the SignalR team at Microsoft is constantly striving to improve its product, so it frequently issues software updates. The numbering of these versions is usually of the 2.0.x or 2.x.0 type. Besides corrections, these updates might include some new or improved features, but not breaking changes or significant modifications of the development APIs.

In any case, the contents of the book will still be valid after updating components to these new versions, although it will obviously be necessary to modify the existing references in the source code of the examples, especially in the case of references to script libraries.

Thus, if we have a code such as the following:

<script src="/scripts/jquery.signalR-2.0.0.min.js"></script>

after installing version 2.0.1 of SignalR, it should be changed to this:

<script src="/scripts/jquery.signalR-2.0.1.min.js"></script>

Installing the code samples

To install the code samples, just download the file indicated and decompress it into a folder in your system.

Using the code samples

After decompressing the file, a folder structure will have been created. The folders are organized in the same order as the chapters in the book, starting with Chapter 4, which is where we will begin to look at examples of code:

Chapter 4 – Persistent connections
Chapter 5 – Hubs
Chapter 6 – External access

Inside each of these folders you can find a subfolder for each sample project included. These subfolders are numbered in the order that the concepts are dealt with in the book:

Chapter 8 – Scaling
1-AzureServiceBus
2-SqlServer

Inside these folders you can find the specific solution file (*.sln) for each example. The solutions are completely independent of each other and include a fully functional example that is ready to be run (F5 from Visual Studio), although in some cases it will be necessary to make some prior adjustments in configurations. In such cases, detailed instructions are always given for this on the main page of the project or in a readme.txt file.

Acknowledgments

As trite as it might sound, a book such as this would not be possible without the collaboration of many people who have helped with their time and effort for it to become a reality, and it is only fair to dedicate them a special word of thanks.

In particular, I would like to thank my editor at campusMVP.net, Jose M. Alarcón (on Twitter at @jm_alarcon) for his involvement, his ability in the project management, coordination, and revision, as well as for his sound advice, all of which have led us here.

Javier Suárez Ruíz’s (@jsuarezruiz) collaboration has also been essential, for his contributions and SignalR client implementation examples in non-web environments such as Windows Phone or WinRT.

I would like to thank Victor Vallejo, of campusMVP.net, for his invaluable help with the text.

On the part of Microsoft, I want to give thanks to the acquisitions editor, Devon Musgrave, for his interest in this project from the start, without which this book would have never been made. I also want to thank project editor Carol Dillingham for her expert work. Thanks go out to technical reviewer Todd Meister, copy editor Richard Carey, project manager Sarah Vostok of nSight, and indexer Lucie Haskins. And thanks to Sarah Hake and Jenna Boyd of O’Reilly Media for their support.

Lastly, I would like to thank Damian Edwards and David Fowler for their invaluable input. It is a privilege to have been able to benefit from the suggestions and contributions of the creators of SignalR to make this book as useful as possible.

Errata & book support

We have made every effort to ensure the accuracy of this book and its companion content. Any errors that have been reported since this book was published are listed at:

http://aka.ms/SignalRProg/errata

If you find an error that is not already listed, you can report it to us through the same page.

If you need additional support, email Microsoft Press Book Support at .

Please note that product support for Microsoft software is not offered through the addresses above.

We want to hear from you

At Microsoft Press, your satisfaction is our top priority, and your feedback our most valuable asset. Please tell us what you think of this book at:

http://aka.ms/tellpress

The survey is short, and we read every one of your comments and ideas. Thanks in advance for your input!

Stay in touch

Let’s keep the conversation going! We’re on Twitter: http://twitter.com/MicrosoftPress.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.254.61