Chapter 11. Building the Support Case System

In the real world, it is difficult to have two devices (the server and mobile device) remain connected online throughout the use of an application. Mobile devices are meant to be, as the term suggests, mobile—end users will use the application you've developed underground in subways, in airplanes thousands of feet in the air, or during train rides miles away from civilization.

As you've seen in the previous chapter, web services work great in disconnected scenarios. Your mobile application could work with local data, and only needed to go online when it had to receive or send updates to/from the server. In other words, you had to be online to make a web service call.

But what if your application needs to still send updates to the server, even when you are not connected to your server? Consider the following example—as a technician on the move, you are given a mobile application that lists down, in real time, the available jobs that you can choose to accept. Let's say you are entering an area where the local Internet Wi-Fi connection is choppy at best. If you use web services, accepting a job would quickly become a frustrating affair—you find that you can't accept a job unless you're online.

In such scenarios, some form of disconnected messaging is required. When you accept a job, and you are not connected to the server, your application should store this request as a message on the device temporarily. Whenever the device has the chance to get online, it should automatically send these messages on their way again to the server. Microsoft provides a technology called the Microsoft Messaging Queue Service (MSMQ) that does precisely this, all "under the hood," and it is completely transparent to your application.

In this chapter, you will create a mobile support case system (where users can accept a job from a list of open jobs) that relies on MSMQ technology for all communications between the mobile device and server. You will learn:

  • How to set up MSMQ on the mobile device and the server
  • How to use MSMQ to provide reliable disconnected messaging services—send data to a remote device even when it is offline
  • How to use MSMQ in a "broadcast" model—broadcasting data to multiple mobile devices
  • How to send entire business objects between devices through MSMQ
  • How to use the accompanying MSMQ tools on the mobile device and server to manage your messaging queues and their messages

Introduction to MSMQ and the support case system

The MSMQ service is a component provided free of charge by Microsoft, and is available to both the PC and mobile device platforms. It is essentially a Windows service—you can see it in your list of running services on your development PC.

Introduction to MSMQ and the support case system

At the core of MSMQ lies the concept of messages, which are packets that hold information (typically represented in XML), and queues, the objects that temporarily hold messages before they are processed.

A client application would typically send a message to a server, where it would end up in a queue on the server. The application on the server would inspect this queue periodically, and upon finding any messages inside, it would remove them from the queue for processing. You can create as many queues as you like, and each message can be designated for a specific queue (by name).

In the support case application, for example, the mobile device and the server will have a queue each. This allows both mobile device and server to send and receive data. MSMQ supports the following protocols for data transmission:

  • TCP
  • HTTP
  • HTTPS

This is depicted in the following diagram:

Introduction to MSMQ and the support case system

The diagram shows what happens in an always connected environment. However, there are times when a message cannot be delivered due to the recipient device being offline. When this happens, MSMQ will internally create an Outgoing queue, and place the undelivered message in this queue. When the recipient device reconnects, the message is sent out and subsequently removed from the Outgoing queue. This facility happens "under the hood" and is transparent to your application. The following diagram depicts this functionality:

Introduction to MSMQ and the support case system

In the support case system that you are going to build in this chapter, you will use MSMQ to broadcast a job to all the devices every time the user adds a new job at the server side.

The client application running on the mobile device will update its display of open jobs, and the user can then choose to accept a job from this list. The client application will then use MSMQ to transmit this command back to the server, where the job list display will also be updated.

Let's start by taking a look at how you can get MSMQ set up on your mobile device.

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

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