362 Chapter 8 • Wireless Enabling Your Big Bandwidth Site my($ua,$dev) = split(/:/,$_); if ($uagent eq $ua) { $type = $dev; } } close(DB); return $type; } The script in Figure 8.9 provides the basic building blocks to detect both the language that the client can accept and the type of device requesting the content (against a predefined list of user agents and device types). By using the results of these two subroutines, it is possible to alter the presentation of retrieved data depending on the properties of the client. You could add additional methods to this library to extract the number of softkeys a device has, or to collect device-specific identification strings (such as the subscriber_no displayed in the header for the UP.Browser, or the %deviceid of a Palm VII PDA.) Which environmental variables you choose to examine and how you branch your code is implementation-specific, and it is possible to build WML that works on all devices, but most instances will benefit from some code branching or redirection. Implementing Wireless Graphics In general, wireless images will be of lower resolution, color depth, and file size than their WWW counterparts.We will discuss the common file formats for images sent over the wireless Internet, how to maintain accessibility when images may not be available, and some of the more common methods for creating images in the appropriate wireless format. File Formats Several different image file formats are supported on mobile devices.Two formats with which any Webmaster will be familiar are GIF and JPEG.A format with which traditional Webmasters may not be familiar is that of the Wireless Bitmap (WBMP), a one-bit depth (two-color) bitmap.Which particular device supports www.syngress.com Figure 8.9 Continued 159_wg_wi_08 10/22/01 5:21 PM Page 362 Wireless Enabling Your Big Bandwidth Site • Chapter 8 363 any particular image format is a much harder thing to discern. Some devices sup- port only WBMP images, and others support GIF and JPEG and not WBMP. WML that is transcoded to HDML via a gateway may have all of the images stripped out of it. Maintaining Accessibility It is important to maintain accessibility of our site to devices that do not support the technologies that we are using.This applies to images as well. It is absolutely imperative to make use of the ALT attribute of the <IMG> tag when building our site so that users accessing the site with non-image capable browsers can still gain value from the site (after all, we’re building it for the users, right?). Converting Your Images There are several means for creating images that are viewable by mobile devices. Teraflops (www.teraflops.com/wbmp/) provides an online converter that converts images uploaded via a Web browser.A search for “WBMP” on Tucows (www.tucows.com) will turn up a wide variety of free and/or shareware tools available for download. www.syngress.com 159_wg_wi_08 10/22/01 5:21 PM Page 363 364 Chapter 8 • Wireless Enabling Your Big Bandwidth Site Summary While it may not be possible to magically convert your existing Website in all its glory to a wireless version, it is certainly possible to add wireless capabilities to an existing Website without a complete overhaul. In this chapter, we have covered the means of adding wireless capabilities at the directory, site, and server level to existing Web server environments for both Apache and Microsoft IIS; and discussed the issues involved with making an existing site available to mobile users. We have discussed the means of detecting wireless devices and redirecting users to appropriately formatted content, using PHP and Perl, and based on information contained in the environmental variables HTTP_USER_AGENT and HTTP_ACCEPT.We also examined a small library written in Perl that can be used to detect language types and devices in order to branch display code according to the user’s browser. In addition, we discussed the issues surrounding the automated conversion of HTML to WML, and discussed wireless graphics and some tools available for graphics conversion. Solutions Fast Track Defining WAP MIME Types It is important to consider the market for which you are delivering content, and to define the appropriate MIME types for the devices used by your users. There are several options for defining MIME types under the most common Web servers on the market. MIME types may be defined and Wireless content may be deployed at the directory, site, or server level. WAP MIME types are defined in the same manner as any other MIME type. Detecting WAP Devices WAP devices send the same type of header information to Web servers as desktop browsers do. www.syngress.com 159_wg_wi_08 10/22/01 5:21 PM Page 364 Wireless Enabling Your Big Bandwidth Site • Chapter 8 365 HTTP_ACCEPT can be used to detect the language that a given browser can accept. HTTP_USER_AGENT can be used to differentiate browsers depending on the reported name of the browser. A combination of HTTP_ACCEPT and HTTP_USER_AGENT can be used to redirect devices to appropriate content, or to profile devices for formatting. Optimizing Content Distribution Regardless of the technical issues of how you manage your content, take a critical look at your current Web site and consider what you want to provide to your wireless users. It is possible to automatically format existing sites, but with dubious results. WAP sites may be set up with the same flexibility as Web sites. Delivering Wireless Data Mobile users are more often in need of data rather than content. It is important to separate content from presentation for data applications. Build modules that enable device profiling and accordingly allow for different presentations of dynamic data from the same source. Implementing Wireless Graphics Several different formats are supported, including common Web formats for some devices. Ensure accessibility by using <ALT> tags on all images, and conserve bandwidth by only using graphics when necessary. Online and desktop converters are available to automatically convert your existing images. www.syngress.com 159_wg_wi_08 10/22/01 5:21 PM Page 365 366 Chapter 8 • Wireless Enabling Your Big Bandwidth Site Q: Will I need to install a WAP gateway to serve out my site? A: No.You only need to configure your Web server to deliver the appropriate content. Q: What kind of server-side scripting languages can I use to create wireless con- tent? A:You can use ASP, PHP, JSP, Perl, Python, Ruby, or any other server-side scripting language to print WML to a browser. Q: Do I need to branch my WML code for different browsers? A: Not necessarily. If your code is well designed and valid, it should display on any browser that supports WML. However, there are some differences between browsers that do affect usability. Depending on the nature of your implementa- tion, you may want to branch your code for a better user experience. www.syngress.com Frequently Asked Questions The following Frequently Asked Questions, answered by the authors of this book, are designed to both measure your understanding of the concepts presented in this chapter and to assist you with real-life implementation of these concepts. To have your questions about this chapter answered by the author, browse to www.syngress.com/solutions and click on the “Ask the Author” form. 159_wg_wi_08 10/22/01 5:21 PM Page 366 Microsoft Mobile Internet Toolkit Solutions in this chapter: ■ Overview of the .NET Mobile Architecture ■ Introduction to ASP.NET ■ Developing Mobile Web Forms ■ Accessing Data with ADO.NET Summary Solutions Fast Track Frequently Asked Questions Chapter 9 367 159_wg_wi_09 10/22/01 5:29 PM Page 367 368 Chapter 9 • Microsoft Mobile Internet Toolkit Introduction In the earlier chapters you have seen the use of the Wireless Markup Language (WML) and WMLScript for creating mobile applications and services. In this chapter, we will take a look at the Microsoft Mobile Internet Toolkit and how it can aid in mobile application development.The Microsoft Mobile Internet Toolkit is a set of mobile framework extensions that have been added to ASP.NET Web Forms.With these extensions, a mobile application developer can create compelling mobile applications without worrying unduly about the limitations of the various target devices.The current situation in mobile application development is that var- ious devices have a very different look and feel, and often developers have to spend huge amounts of time tailoring their applications to run on the target devices.A typical solution is to code the content of your application in XML and use XSLT to transform the content into a target markup language like WML. Rather than focusing on the user interface issues, the Microsoft Mobile Internet Toolkit provides a set of APIs to let the developer concentrate on the functionality of the application. During runtime, the Microsoft Mobile Internet Toolkit API will automatically detect the kind of device accessing the application and generate the appropriate codes to run on it. To get the full benefit from this chapter, you should know the basics of Microsoft ASP for developing Web applications. Overview of the .NET Mobile Architecture The Mobile Internet Toolkit is built on the Microsoft ASP.NET Web Forms (which we’ll discuss in the next section). It is an extension to the ASP.NET model.The toolkit includes a set of Mobile Controls that is executed by the Mobile Internet Controls runtime during the execution phase.The key feature of the runtime is its ability to recognize the different types of devices accessing the forms and to generate dynamically the codes that the device can understand. The toolkit supports such controls as Calendar, Label, SelectionList, and Textbox. Since the toolkit is an extension of ASP.NET Web Forms, it supports languages like VB .NET, C#, and JScript.NET. www.syngress.com 159_wg_wi_09 10/22/01 5:29 PM Page 368 www.syngress.com Devices Supported by the Microsoft Mobile Internet Toolkit According to Microsoft, the Microsoft Mobile Internet Toolkit SDK has been tested with the following devices: ■ Mitsubishi T250 ■ Nokia 7110 ■ Pocket PC with Microsoft Pocket Internet Explorer version 4.5 ■ Siemens C-35i The following additional devices and simulators have had limited testing: ■ Ericsson R380 ■ Microsoft Internet Explorer 5.5 ■ Microsoft Internet Explorer 6.0 ■ Mitsubishi D502i ■ NEC N502i ■ Nokia 6210 ■ Palm VIIx ■ Palm V ■ Panasonic P502i ■ RIM Blackberry 950 ■ RIM Blackberry 957 ■ Samsung 850 ■ Siemens S-35i ■ Sprint Touchpoint phone System Requirements To develop mobile applications using the Mobile Internet Toolkit, your system requirements are as follows: Microsoft Mobile Internet Toolkit • Chapter 9 369 159_wg_wi_09 10/22/01 5:29 PM Page 369 370 Chapter 9 • Microsoft Mobile Internet Toolkit ■ Microsoft Windows 2000 Server/Advanced Server/Professional SP1 ■ Internet Information Server ■ Microsoft Internet Explorer 6.0 ■ .NET Framework Beta 2 (including ASP.NET) ■ Mobile Internet Toolkit Beta 2 NOTE Microsoft Internet Explorer 6.0 is installed automatically when you installed the .NET framework SDK. Starting from Beta 2 of the toolkit, you can now make use of the visual tools in Visual Studio .NET (Beta 2) to develop your mobile application. However, all the code in this chapter has been developed using a text editor. Obtaining and Installing the Microsoft Mobile Internet Toolkit The current release of the Microsoft Mobile Internet Toolkit is Beta 2.You can download a copy of the Microsoft Mobile Internet Toolkit Beta 2 from the fol- lowing URL: http://msdn.microsoft.com/downloads/default.asp?URL=/code/ sample.asp?url=/MSDN-FILES/027/001/516/msdncompositedoc.xml. NOTE The Beta 1 version of the Microsoft Mobile Internet Toolkit was known as the .NET Mobile Web SDK. To install the toolkit, simply double-click on the downloaded file and follow the instructions from the installation wizard; start by accepting the licensing agreement. In the Setup Type screen, choose to install the Complete setup to install all the program features, rather than choosing the Custom setup. Click the Next button, and when the program completes the installation the wizard will bring you to a final screen that allows you to exit by clicking Finish. Once the www.syngress.com 159_wg_wi_09 10/22/01 5:29 PM Page 370 Microsoft Mobile Internet Toolkit • Chapter 9 371 toolkit is installed, you will find a shortcut called Mobile Internet Toolkit Overview created on your desktop. NOTE Before installing the Microsoft Mobile Internet Toolkit, you must first install the .NET framework SDK. The .NET framework SDK can be obtained from http://msdn.microsoft.com/downloads/default.asp?URL=/ code/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml. The toolkit comes with documentation as well as sample code.To use the QuickStart Tutorial provided with the toolkit, you must configure a virtual direc- tory on your Web server to point to the correct directory path.Table 9.1 indi- cates the virtual directory details. Table 9.1 Virtual Directory to QuickStart Tutorial Virtual Directory MobileQuickStart Name Directory Path C:\Program Files\Microsoft.Net\Mobile Internet Toolkit\ QuickStart (Please specify the default document as Default.aspx) If the virtual directory is configured correctly, you will see the screen shown in Figure 9.1 using the URL http://localhost/MobileQuickStart. Introduction to ASP.NET Since the Microsoft Mobile Internet Toolkit is based on ASP.NET, it is important for you to have a good understanding of how ASP.NET works and how it is different from ASP. Before we look into the technical details of working with ASP.NET, let’s consider a typical situation when writing a Web application with ASP. As you are probably aware, HTTP is a stateless protocol.Although being stateless has its benefits, such as reducing the resources on the server side, it often poses headaches for Web developers. In the following example, we will illustrate one of the problems with statelessness commonly faced by ASP developers. In this example, we have a form and we need users to fill it in and submit it for processing. Our form may look like Figure 9.2. www.syngress.com 159_wg_wi_09 10/22/01 5:29 PM Page 371 . http://msdn.microsoft.com/downloads/default.asp?URL=/ code/sample.asp?url=/msdn-files/027/000/976/msdncompositedoc.xml. The toolkit comes with documentation as well as sample code .To use the QuickStart Tutorial provided with the toolkit, you must configure a virtual direc- tory on your Web server to point to the. http://msdn.microsoft.com/downloads/default.asp?URL=/code/ sample.asp?url=/MSDN-FILES/027/001/516/msdncompositedoc.xml. NOTE The Beta 1 version of the Microsoft Mobile Internet Toolkit was known as the .NET Mobile Web SDK. To install the toolkit, simply double-click on the downloaded file and follow the instructions. Microsoft Mobile Internet Toolkit The current release of the Microsoft Mobile Internet Toolkit is Beta 2.You can download a copy of the Microsoft Mobile Internet Toolkit Beta 2 from the fol- lowing