Proceed to WirelessDevNet Home Page
Publications, e-books, and more! Community Tutorials Store Downloads, tools, & Freebies! IT Career Center News Home
newnav.gif

Newsletters
EMail Address:



   Content
  - Articles
  - Columns
  - Training
  - Library
  - Glossary
 
   Career Center
  - Career Center Home
  - View Jobs
  - Post A Job
  - Resumes/CVs
  - Resource Center
 
   Marketplace
  - Marketplace Home
  - Software Products
  - Wireless Market Data
  - Technical Books
 
   News
  - Daily News
  - Submit News
  - Events Calendar
  - Unsubscribe
  - Delivery Options
 
   Community
  - Discussion Boards
  - Mailing List
  - Mailing List Archives
 
   About Us
  - About WirelessDevNet
  - Wireless Source Disks
  - Partners
  - About MindSites Group
  - Advertising Information
 
INDEX
>Introduction
>Understanding the Wireless Markup Language
>Valid WML Elements
>Building Applications With WML
>Creating A WML Deck
>Calling A Server Script
>Conclusion
 

Calling A Server Script

Without the ability to perform server transactions, WML would only serve to provide a standardized way to display text on a client. Adding in the ability to dynamically connect to remote servers opens up every WAP device to the world of Internet messaging, enterprise data, and e-commerce. WAP devices interact with these data sources through a WAP gateway as mentioned in our WAP Overview tutorial. This gateway must interface with a carrier such as CDMA, GSM, or GPRS. However, it is possible to install and test gateway products in conjunction with popular Web servers (such as Microsoft Internet Information Server or Apache) on your LAN. This tutorial won’t go into the details of installing and configuring a gateway (see our WAP Tools Comparison tutorial for more information) but to eliminate a very common beginner’s error, we’ll remind you to be sure to add the following MIME types to your Web server:


WML text/vnd.wap.wml wml 
WMLScript text/vnd.wap.wmlscript wmls 

Once this has been done, you’re ready to go! We’ll now create a very simple example which allows the user to select an option and then retrieve data from a server based on that option. For this example, we’re using Microsoft Active Server Pages (ASP) technology for the server-side scripting since that is the technology supported by our hosting provider. You could just as easily use other popular server scripting tools such as Java Servlets, JavaScript, or Perl. Listing 2 gives the WML source code for our new deck. It basically contains a single

<select>
element that gives the user a few options for retrieval. The
<go>
element for this select list calls a server script with the appropriate arguments.

Listing 2 - WMLExample2.wml


<?xml version='1.0'?>
<DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml"> 
 
<wml> 
 
	<card id="Order" title="Query Inventory"> 
		<p> 
		<select name="Items" title="Items">
			<option value="Books">Books</option>
			<option value="Music">Music</option>
			<option value="Video">Video</option>
			<option value="Software">Software</option>
		</select>
		</p> 
		<do type="accept" label="Query">
			<go href="http://127.0.0.1/WML/Inventory.asp" method="post">
				<postfield name="Items" value="$(Items)"/>
			</go>
		</do>
	</card> 
</wml>

The server script (shown in Listing 3) examines the input and produces WML output to be displayed on the device.

Listing 3 - Inventory.asp


<% 
Dim Body

If Request.Form("Items") = "Books" Then
	Body = "You selected Books!"
ElseIf Request.Form("Items") = "Video" Then
	Body = "You selected Video!"
ElseIf Request.Form("Items") = "Software" Then
	Body = "You selected Software!"
ElseIf Request.Form("Items") = "Music" Then
	Body = "You selected Music!"
End If

Response.ContentType = "text/vnd.wap.wml"%>

<?xml version='1.0'?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card>
<p>

<%Response.write(Body)%>

</p>
</card>
</wml>

Figures 5 and 6 show the Music option being selected and the resultant screen retrieved from the ASP script.


Figure 5

Figure 6

A few things should be mentioned for those wishing to run this example on their local Web server. You must register the proper MIME types with your Web server so that WML content can be properly sent. The two MIME types that should be registered are:


.wml	text/vnd.wap.wml
.wmls	text/vnd.wap.wmlscript

If you’d like to use Wireless Bitmap images (the image format supported by WAP), also add:


.wbmp		image/vnd.wap.wbmp

Finally, I’d like to mention one error I continually received when developing this example using the Nokia WAP Toolkit 1.2. I’ve seen numerous postings on WAP Development boards concerning this error so I thought I’d explain the problem and solution here. Although I registered the MIME types with IIS 4.0, I still received the message "Mime type not supported." It turns out that even though I was loading the WML source via my local machine’s Web server, the Toolkit was switching over to a file://-based URL since the file was local to my machine. When I then attempted to run the script using href="Inventory.asp", I got the error. Switching the href over to http://127.0.0.1/WML/Inventory.asp forced the loading of the script through the Web server which allowed for proper recognition of the WML MIME types.

Next: Conclusion
 

Sponsors

Search

Eliminate irrelevant hits with our industry-specific search engine!









Wireless Developer Network - A MindSites Group Trade Community
Copyright© 2000-2010 MindSites Group / Privacy Policy
Send Comments to:
feedback@wirelessdevnet.com