Mobile Reference Model: Tour of the Mobile Reference Application


Overview

This article introduces Mobile Reference Application, describes how to install and use it, and gives a technical overview of the application's architecture.

Mobile Reference Application demonstrates how to design and implement a solution that uses the Mobilized Reference model. Designed around the scenario of a real estate agency, Mobile Reference Application allows real estate agents to upload and download property information among servers and desktops and mobile client devices.


Installation

The Mobile Reference Application has been tested on Windows* XP. The application may function on other operating systems, so long as the required prerequisite software is installed.

To function properly, the Mobile Reference Application requires the following software to be installed on the developer machine:

  • Internet Information Server*
    The Mobile Reference Application client application communicates with a Web service to store and retrieve information. Internet Information Server must be installed, or the Web service will not function.
  • Microsoft Visual Studio .NET 2003*
    The reference application requires the Microsoft .NET Framework* V1.1, which is installed with Visual Studio .NET 2003. The reference application also includes full source code, packaged as Visual Studio .NET 2003 projects.

    If you have not installed Visual Studio .NET 2003, but you do have Visual Studio .NET, then you can take advantage of the Microsoft Visual Studio .NET* 2003 Upgrade Offer.
  • Microsoft SQL Server* or MSDE*
    The application uses both a client-side and a server-side database. Because of this design characteristic, you must have MSDE or SQL Server installed. If you have installed MSDE as part of the .NET QuickStart Tutorials, the application will use this instance.
  • Web Service Enhancements for Microsoft .NET 1.0 (SP1)
    The application uses Web Service Enhancements to transfer binary files between the client and server portions of the application. Web Service Enhancements can be downloaded from the following location:
    http://msdn.microsoft.com/en-us/library/dd560530.aspx*
    Web Service Enhancements 1.0 SP1 was used to develop Mobile Reference Application.
  • Windows Media Player* 9 Series
    The application depends on functionality provided by Windows Media Player 9 Series for scene-recognition functionality.
  • DirectX* 9.0a Software Developer Kit (SDK)
    The scene-recognition functionality requires the APIs provided by the DirectX 9.0a SDK, which is available for download from the following location:
    http://msdn.microsoft.com/en-us/directx/default.aspx*

 

Once the prerequisites are installed, you can download the Mobile Reference Application zip file and extract the contents. In the root folder for the application, you will find MRASetup.exe. Execute this program to install the client and server Mobile Reference Application databases and set up the Mobile Reference Application Web service.

Once the setup has completed, you can open the solution file for Mobile Reference Application (MobileReferenceApplication.sln).

The application was written using C#* but could just as easily have been written in other .NET languages such as Visual Basic .NET*.


Business Requirements

Mobile Reference Application is designed to assist users in the real-estate field by meeting the following business requirements:

  • When a house goes on the market, a real estate agent can collect information on the house and add that information to the system's database.
  • A wide variety of information is kept track of for each house, including construction style, roof type, lot size, garage size, number of bathrooms and bedrooms, levels, etc.
  • Real estate agents can take digital video recordings or still pictures of each house and integrate them into the Mobile Reference Application environment to show to prospective buyers.
  • Real estate agents can perform searches for houses that meet specific buyer criteria, such as location and price.
  • Real estate agents can perform credit checks on prospective buyers.

 


User's Guide to Mobile Reference Application

Main Form: When the application loads, the user is greeted with the main form:



The main form consists of a tab control with two tab pages: Search for Houses and Credit Report.

Performing a Search: Using the search function is quite simple. Simply enter the desired search criteria, such as the city, state, zip code, and price range. Then click the Search button. The application will then call a Web service that returns every house that matches the criteria. The user can enter as many or as few search criteria as they wish. If no criteria are entered, all houses are returned. The information is downloaded and stored in the local database. This way, if the connection is temporarily lost, the data will still be accessible.



Once a search is completed and the results are displayed in the list view control, select a house from the list view control and click the More Info button. This displays the House form. In this form, you can view all the available information about the ho use:



The user can also modify the data from this screen. Clicking OK will save any changes to the local database, which is then uploaded to the server using a Web service.

Running a Credit Report: Mobile Reference Application also allows real estate agents to perform a credit check on a prospective buyer. Simply switch to the Credit Report tab and enter the applicant's name and address. Then click the Get Credit Report button, and the application will call out to a credit report Web service:



The credit report is then displayed in the Credit Report Form:



Note that a credit check cannot be performed locally, and a Web service must be called to run the credit report. If the connection is lost, the user will not be able to run a credit report, but the rest of the application remains functional.

Data Menu: From the Data menu, the user can add new houses, manually force synchronization with the database server, download all house photos as a batch job, download all house videos as a batch job, and clear the local cache of data:



Adding a New House to the Database: Selecting the Data | Add New House menu command will bring up the Add New House form. Real estate agents can enter a wide variety of information for each house, including its size, price, location, and description. Mobile Reference Application is designed to be as flexible as possible. The user is free to enter as much or as little information as they like. When you are done entering information, click the OK button to save the data:



Multimedia: Although multimedia is a great feature for the user, it presents technical challenges to the developer. Because videos can be large, and wireless connections are potentially slow, it may not be desirable for the application to automatically assume that the agent will want to download every video available for every house.

Imagine a situation where a real estate agent performs a search that returns dozens of houses, and each of these houses has a 10 – 20 megabyte walkthrough video. Automatically downloading all videos can take a very long time.

There are a number of ways to address this issue. One option is to let the user download each video one at a time. A second option is to let the user manually download all videos at the same time. To make the application easy to use and flexible, Mobile Reference Application is designed to allow both options.

To download a video for a particular house, select the house in the list view control and click the More Info button. On the Edit Existing House form, switch to the Video tab and click the Download from Server button:



To download all videos at once, select the Data | Download All Videos menu command:



Clear Local Cache: The Clear Local Data menu command deletes all records from the local database and deletes all photos and videos from the local file system. Although all this data is kept on the server, it is important that the user be prompted before clearing the local data cache. Otherwise, all the data will have to be downloaded again from the server using the Search functionality:


Technical Overview

Real estate agents cannot be tied to their desk at the office. They are on the go and need to travel to many different locations to give tours to prospective buyers. Although wireless Internet access is starting to become more popular, it is still far from ubiquitous. Thus, the client application may or may not have an active or reliable connection to the server. This reality cannot be ignored, and it presents one of the technical challenges this solution must solve. If the application cannot run because the connection is lost, a prospective sale can easily be lost. Mobile Reference Application is designed to run whether it is online or offline. This arrangement is called the Occasionally Connected Computing (OCC) model.

Mobile Reference Application presents one suitable technique for developing an OCC application; others are possible.

Database: Both the client and server portions of the Mobile Reference Application use a SQL Server (or MSDE) database. When a real estate agent performs a search, all houses are immediately downloaded to the client-side database. As the real estate agent adds new houses or changes existing ones, the data is saved to the local database first and then uploaded to the server.

The application periodically monitors whether it is online or offline. If a real estate agent makes or changes a listing while the application is offline, Mobile Reference Application will upload the changes the next time the connection is available.

Web Service Enhancements: In addition to taking a still picture of a house, a real estate agent can use a digital video camera to record a video of a house. This allows the real estate agent to create multimedia walkthroughs of houses to show to prospective buyers.

When the real estate agent attaches the digital video camera to his or her laptop, Mobile Reference Application attempts to locate the camera and search for video files. If the search is successful, the Browse for Folder dialog on the house form will default to that directory. The real estate agent can then select the particular video to use and upload that file to the Web server using a Web service.

Web services do not handle binary files by default, however. After all, Web services are based on XML, which is text. To extend Web services to handle binary information, Web Service Enhancements technology is used. This is a .NET class library that provides additional functionality for creating more powerful Web services, such as WS-Security, WS-Routing, WS-Attachments, and Direct Internet Message Encapsulation (DIME).

In particular, Mobile Reference Model takes advantage of the DIME specification to upload and download photos and videos of a house.

Introduction to DIME: The DIME specification allows a Web service to transport binary data as an attachment. This is somewhat analogous to attaching a binary file to a text e-mail message.

To take advantage of DIME, both client and server need to have a reference to microsoft.web.services.dll. This .NET library is installed as part of the Web Service Enhancements setup program. To simplify coding, Mobile Reference Application adds a using statement to the top of each source code file that uses DIME:

using Microsoft.Web.Services.Dime;

 

DIME – Client Side: After adding a reference to microsoft.web.services.dll, the client application needs a Web reference to the Web service. The process of adding a Web reference to a DIME-enabled Web service is the same as adding a Web reference to any other Web service, with one important difference. You must manually edit the Web reference's Reference.cs file.

By default, the Reference.cs file does not display in Visual Studio .NET 2003's Solution Explorer. Therefore, to see this file in Solution Explorer, click the Show All Files button:



Then open the Reference.cs file, scroll to the first line of the Web service class, and change the base class to Microsoft.Web.Services.WebServicesClientProtocol. For example:

public class DataWebService : 

Microsoft.Web.Services.WebServicesClientProtocol

 

If this line is not changed, the client will not be able to handle DIME attachments. Also be aware that if you update the Web reference in Visual Studio .NET, this line will be overwritten. Therefore, every time you update a Web refe rence to a DIME-enabled Web service, you must remember to change the class to inherit from Microsoft.Web.Services.WebServicesClientProtocol.

To upload the house video to the Web server, Mobile Reference Application first opens a FileStream object to the video file:

//Upload new videos from client to server

System.IO.FileStream stream = System.IO.File.OpenRead(path
+ h.Video);

 

The expression path + h.Video contains the full pathname of the file. The next step is to instantiate a DimeAttachment object, indicating the type of attachment in the constructor:

DimeAttachment attachment = new DimeAttachment("0",

TypeFormatEnum.MediaType, stream);

 

Once the DIME attachment has been created, add it to the Web service's RequestSoapContext object:

ws.RequestSoapContext.Attachments.Add(attachment);

 

Finally, upload the file using Web service's UploadVideo method. In the following line of code, ds is a DataSet containing the house to which the video file should be associated:

ws.UploadVideo(ds);

 

DIME – Server Side: The server portion of Mobile Reference Application also requires a reference to microsoft.web.services.dll. In addition, the solution's Web.config file must be modified to include a reference to Web Service Enhancements. The following must be added between the tags:





"Microsoft.Web.Services.WebServicesExtension,

Microsoft.Web.Services, Version=1.0.0.0,

Culture=neutral,

PublicKeyToken=31bf3856ad364e35"

priority="1" group="0" />





 

The element's type attribute must be on one single line. Line breaks are not allowed. The example shown in this article uses line breaks for readability's sake. Remember to remove these line breaks when adding to the Web.config file.

Mobile Reference Application then exposes an UploadVideo Web method, which allows the client to upload a video as a DIME attachment to the server:

[WebMethod]

public void UploadVideo(dsHouses changedHouse)

{

dsHouses.HousesRow h = changedHouse.Houses[0];

//Get video attachment.

Stream contents =

HttpSoapContext.RequestContext.Attachments[0].Stream;

byte[] data = StreamToByteArray(contents);

//Save video as a file.

string filename = h.Video;

string videosPath = Server.MapPath("") + "Videos";

string pathname = videosPath + filename;

if (File.Exists(pathname))

File.Delete(pathname);

FileStream fileStream = File.OpenWrite(pathname);

fileStream.Write(data, 0, data.Length);

fileStream.Close();

File.SetLastWriteTime(pathname, h.VideoModified);

//Update database.

DataAccess._dataAccess.UpdateHouseVideo(h, null);

}

 

To access the attachment, HttpSoapContext.RequestContext has an attachment collection. The video file is read in as a stream and then converted to an array of bytes using a StreamToByteArray function:

private byte[] StreamToByteArray(Stream stream)

{

MemoryStream tempStream = new MemoryStream();

int byteAsInteger;

while ((byteAsInteger = stream.ReadByte())!= -1)

{

tempStream.WriteByte(((byte)byteAsInteger));

}

return tempStream.ToArray();

}

 

Back in the UploadVideo routine, the video is saved to the file system, and the database is updated to reference the newly uploaded video:

//Save video as a file.

string filename = h.Video;

string videosPath = Server.MapPath("") + "Videos";

string pathname = videosPath + filename;

if (File.Exists(pathname))

File.Delete(pathname);

FileStream fileStream = File.OpenWrite(pathname);

fileStream.Write(data, 0, data.Length);

fileStream.Close();

File.SetLastWriteTime(pathname, h.VideoModified);

//Update database.

DataAccess._dataAccess.UpdateHouseVideo(h, null);

}

 


Conclusion

Although this article provides only a brief introduction to the Mobile Reference Model, it covers a wide variety of topics and technologies. It began with an overview of the Mobile Reference Application, its business requirements, and how it serves as a sample application for real estate agents. It also explained how to install Mobile Reference Application, including prerequisite software requirements.

The application was explained from two different perspectives. First, the application was explained from a real estate agent's perspective. A real estate agent would use Mobile Reference Application to show houses to prospective buyers; perform searches on specified criteria; view, add, and change property-listing data; and perform credit checks.

Then, the application was expla ined from a more technical perspective. Mobile Reference Application employs the OCC model, which allows it to be used with or without an active connection to the server. To achieve this, all data is cached to a local database and synchronized back to the Web server when a connection becomes available. The article also explained how to send binary files over a Web service using DIME.


Download Source Code, and the Rest of this Series

This tutorial is part of a series of tutorials and articles from Intel® Developer Services that demonstrates the principles of cross-platform application development for Occasionally Connected Computing. The series uses a reference application called Mobile Reference Application to support the business needs of a hypothetical real-estate agent as she works in a single, unified data space from her desktop PC, her laptop, and her PDA, both online and off. The source code for the reference application is freely available for download.


Resources

Intel, the world's largest chipmaker, also provides an array of value-added products and information to software developers:

  • Intel® Software Partner Home provides software vendors with Intel's latest technologies, helping member companies to improve product lines and grow market share.
  • Intel® Developer Zone offers free articles and training to help software developers maximize code performance and minimize time and effort.
  • Intel Software Development Products include Compilers, Performance Analyzers, Performance Libraries and Threading Tools.
  • IT@Intel, through a series of white papers, case studies, and other materials, describes the lessons it has learned in identifying, evaluating, and deploying new technologies.

Para obtener información más completa sobre las optimizaciones del compilador, consulte nuestro Aviso de optimización.