Push Service with ASP.NET Signalr
Total Page:16
File Type:pdf, Size:1020Kb
Push Service with ASP.NET SignalR Case ModulErp LAHTI UNIVERSITY OF APPLIED SCIENCES Faculty of Technology Information Technology Software Engineering Bachelor’s Thesis Autumn 2017 Maija Kekkonen Lahti University of Applied Sciences Degree Programme in Information Technology KEKKONEN, MAIJA: Push Service with ASP.NET SignalR Case ModulErp Bachelor’s Thesis in Software Engineering, 51 pages Autumn 2017 ABSTRACT The goal of this thesis was to design and implement a prototype of a push service to the ModulERP enterprise resource planning solution. The push service would be used in the browser interface of the system. A push service enables real-time data transfer from a server to a client without the client having to specifically request the data. The research problem was to implement the push service prototype by using the SignalR library. SignalR enables push services to be quickly implemented in ASP.NET environments. The Visual Studio development environment and the SQL Server Management Studio software were used in the implementation. The programming languages used were C#, Visual Basic and JavaScript. The result was a prototype of a push service that could be used to transmit real-time data into the browser interface of the ModulERP system. Popups based on the Telerik user interface component library, a status bar, and a message drop-down menu were added to the browser interface. The prototype has been used in informing users about the zipping of possibly large amounts of files and in informing key users about large attachment files in the system. Key words: ASP.NET, push service, SignalR, web development Lahden ammattikorkeakoulu Tietotekniikka KEKKONEN, MAIJA: Push Service with ASP.NET SignalR Case Modulerp Ohjelmistotekniikan opinnäytetyö, 51 sivua Syksy 2017 TIIVISTELMÄ Opinnäytetyön tavoitteena oli suunnitella ja toteuttaa push-palvelun prototyyppi JL-Soft Oy:n ModulERP-toiminnanohjausohjelmistoon sen selainkäyttöliittymässä käytettäväksi. Push-palvelu mahdollistaa reaaliaikaisen tiedonvälityksen palvelimelta asiakkaalle ilman, että asiakkaan tarvitsee erikseen pyytää palvelimelta dataa. Tutkimusongelma oli push-palvelun prototyypin toteutus käyttäen avoimen lähdekoodin SignalR-kirjastoa, joka mahdollistaa push-palveluiden nopean toteutuksen ASP.NET-ympäristöihin. Toteutuksessa käytettiin Visual Studio –kehitysympäristöä ja SQL Server Management Studio –ohjelmaa. Ohjelmointikieliä olivat C#, Visual Basic ja JavaScript. Tuloksena oli push-järjestelmän prototyyppi, jolla voitiin välittää reaaliaikaista dataa ModulERP-järjestelmän selainkäyttöliittymään. Push- palveluun liittyy selainkäyttöliittymään lisätty statuspalkki ja pudotusvalikko, jossa push-viestit näkyvät, sekä Telerik- käyttöliittymäkomponenttikirjastolla toteutetut ponnahdusviestit. Prototyyppiä on alustavasti hyödynnetty mahdollisesti suurten tiedostomäärien paketoinnissa ZIP-tiedostoihin sekä avainkäyttäjien informoinnissa järjestelmässä olevista suurista liitetiedostoista. Asiasanat: ASP.NET, push-palvelu, SignalR, web-kehitys TABLE OF CONTENTS 1 INTRODUCTION 1 2 THE OPERATING ENVIRONMENT 2 2.1 General Description 2 2.2 Customers 3 2.3 The Need for a Push Service 3 3 SIGNALR 4 3.1 SignalR Basics 4 3.1.1 Transports 4 3.2 Architecture of a System Using SignalR 5 3.2.1 Communication Models 6 3.3 The SignalR Hub Class 7 3.3.1 The OWIN Startup Class 9 3.3.2 Methods That Clients Can Call 12 3.3.3 Calling Client Methods From the Hub 15 3.3.4 Managing Group Membership 17 3.3.5 Connection Lifetime Events 18 3.3.6 The Context Property and the State Object 18 3.3.7 Error Handling 20 3.3.8 Customizing the Hubs Pipeline 22 3.4 The JavaScript Client 23 3.4.1 The Proxy Generated by SignalR 23 3.4.2 Establishing a connection 25 3.4.3 Connection Lifetime Events on the Client 26 3.4.4 Configuring the connection 27 3.4.5 Error Handling and Client-Side Logging 29 3.5 The .NET Client 31 3.5.1 Basics 31 3.5.2 Configuring the Connection 32 3.5.3 Methods That the Server Can Call 33 3.5.4 Invoking Methods on the Server 37 3.5.5 Error Handling and Client-Side Logging 38 4 IMPLEMENTATION: CASE MODULERP 40 4.1 The OWIN Startup Class 40 4.2 Settings 40 4.3 The Database 41 4.4 The Hub Class 42 4.4.1 Connection Lifetime Events 42 4.5 Broadcasting from the Web Service 43 4.6 SignalR on the Client 44 4.6.1 Notifications and Popups 44 4.6.2 Client-side methods callable by the server 46 4.7 Implementations 46 5 CONCLUSION 48 SOURCES 49 APPENDIXES 52 1 INTRODUCTION The goal of this thesis was to design a push service for the ModulERP enterprise resource planning solution maintained by JL-Soft. The library used was ASP.NET SignalR. Reaching the goal involved two sub-goals. The first one was researching the topic in order to find out how to implement a push service with the library. The second one was the actual design and creation of a prototype of the push service. The results of the research are presented in chapter 2. The design and implementation are described in chapter 3. The subject of the thesis was narrowed down to the SignalR library and the implementation of the prototype with it. A push service delivers messages to clients without specific requests from them (Rouse & Steele 2014). This can be contrasted with more traditional HTTP connections, where the client always initiates them (Fielding 1999). Push technology enables clients to be notified instantly as the data becomes available without them needing to, for example, periodically poll for the data. SignalR, the library on which this thesis focuses on, is designed to enable and simplify the creation of a push service in ASP.NET applications. The ModulERP solution is actively developed and maintained by JL-Soft Oy. The company is based in Lahti and was founded in 1990. It employs a little over ten people – the headquarters and developers are in Finland, but there are other employees in other cities and countries. The company has customers around the world. (JL-Soft Oy 2017.) 2 2 THE OPERATING ENVIRONMENT 2.1 General Description ERP solutions, in general, help organizations manage their business by enabling decisions to be data-driven. They often gather and present data about finance, human resource management, inventory management etc. (Rouse 2017.) JL-Soft’s ModulERP solution is based on modules that focus on these and other facets of business. These modules are described next. • The sales module includes features for managing sales orders, shipping, invoicing, products, and offers. The module can be integrated with web stores. Transport documents can be created with it, and the module can also generate reports and statistics. • The purchasing module can generate automatic, timed material purchasing proposals. It also handles invoices and their verification, linking to orders etc. The module generates reports, statistics and forecasts. • The manufacturing module includes features for production planning, work time-tracking, workgroups and work roster. The module can be used to support preventive machine maintenance. An electronic work list can be maintained with the module. Product structure and data can be imported from external product design software. The module generates reports, statistics, and production forecasts. Production can be managed and monitored through the system. • The warehouse module can be used to manage inventory, reclamations, and picking and receiving goods. Inventory can be tracked by batches. This module, like the other modules, also generates reports and statistics. • The accounting module can be used to maintain a sales and a purchase ledger. It can also be used for managing payments and a payroll. 3 • The maintenance module includes features for scheduled maintenance, maintenance contracts, inputting and managing work orders, managing spare parts etc. The module includes a web interface for employees and customers. (JL-Soft Oy 2017.) 2.2 Customers JL-Soft Oy has customers in over 30 countries. The customers represent a range of fields, such as electronics, metal and plastics industry, and import, installation and maintenance. The solution is used in companies of different sizes. (JL-Soft Oy 2017.) Each customer’s ERP solution is separate from the others. The solution can be delivered either as a standalone Windows application, or as a web- based cloud service. Solutions for multiple customers can be located on the same server. 2.3 The Need for a Push Service A push service was identified as a solution to the need for real-time information. This need was apparent especially in the browser-based client interface. The push messages would be sent from JL-Soft’s web service, and received by individual users when using the browser-based client. Each message could be directed to specific users only. There were other requirements in addition to real-time data, such as the buffering of messages when the client application is not running, and the logging of whether the messages have been read or not. 4 3 SIGNALR 3.1 SignalR Basics SignalR is a library that simplifies adding real-time functionality to ASP.NET applications. This means that the server pushes data to clients, instead of clients requesting it. SignalR manages connections automatically. The connection between the client and the server is persistent, in contrast to classic HTTP connections that are re-established every time. (Fletcher 2014a.) 3.1.1 Transports SignalR is an abstraction over transports that do the actual work between the client and the server. There are four transport types: • WebSocket: This is the only transport that establishes a true persistent, two-way connection between the client and the server. • Server Sent Events/EventSource: This transport type receives server-sent events. It connects to a server by using HTTP and receives events in text/event-stream MIME format without closing the connection. (Mozilla Developer Network 2015a; Mozilla Developer Network 2015b.) • Forever Frame: This transport type can be used only with Internet Explorer as the client. It creates a hidden Iframe which makes a request to the server that does not complete.