HOME   ARTICLES   DIRECTORY   CONTACT   ABOUT 

Article Menu
superdotnet originals
Intro Lessons
Tips and Tricks
Data Access
Code-Behind/Controls
Quick Code
General ASP.NET
Windows Forms

All Articles
Reader Comments

Resource Options
Alphabetically
Directory

Hosts
.NET Hosts

More Resources
Namespace List
More MSDN Links
QuickStart Lists


Google



XML Web Services: Part 3: Using with WML
Article Categories: Data Access
Rated: | Number Of Ratings 0 | Add Rating/View Ratings
Page 2

Please make sure that you have read XML Web Services: Part 1: Overview and database interaction and XML Web Services: Part 2: Consumption through ASP.NET as this example builds on the previous examples and code.

One of the great features of .NET is the ease with which data from a Web Service can be integrated into environments such as mobile devices. Using the Mobile Toolkit and the Web Service from our previous examples, you can easily make your data available to WAP/WML devices.

First, a few notes about the Mobile Toolkit (this example provides only a brief overview of the Mobile Toolkit):

  • When using the Mobile Toolkit you must inherit System.Web.UI.MobileControls.MobilePage which identifies the code as a Mobile Page and allows you to use the Mobile Web Form functionality.
  • Register a new tag using the namespace System.Web.UI.MobileControls from the assembly System.Web.Mobile. This allows you to "shortcut" your code and reference the Mobile Controls.
  • A Mobile Page must have at least one mobile form tag.
  • Mobile Controls should be run at the server level.

Below is the code that accesses our XML Web Service and integrates it with our mobile controls.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Import Namespace="System.Xml"%>
<%@ Import Namespace="System.Collections" %>

<%@ Register TagPrefix="mobile" 
Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

<script runat="server">

public void Page_Load(Object sender, EventArgs e){

//create an array to hold values in
ArrayList values = new ArrayList();

//get data from our web service
XmlDataDocument mydata = new XmlDataDocument();
mydata.DataSet.ReadXml("http://www.myservice.com/xmlwebservice_data.asmx/GetData?");

//iterate through specified node list and add to array	
XmlNodeList elemList = mydata.GetElementsByTagName("ArticleName");
for (int i=0; i < elemList.Count; i++){   
values.Add (elemList[i].InnerXml);
}  
	
//bind to datasource
List1.DataSource = values;
List1.DataBind();

}
</script>

<mobile:Form paginate=true runat="server">
<mobile:Label Alignment="center" runat="server">WML WEB Service Example</mobile:Label>
<br/>
<mobile:List runat="server" id="List1"> 
</mobile:List>
</mobile:Form>

First, we're setting our Page directives and registering our tag, and then importing the other namespaces we need to access and manipulate the return XML from our Web Service.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" Language="C#" %>
<%@ Import Namespace="System.Xml"%>
<%@ Import Namespace="System.Collections" %>

<%@ Register TagPrefix="mobile" 
Namespace="System.Web.UI.MobileControls" Assembly="System.Web.Mobile" %>

Page 2



Advertisement

Copyright superdotnet.com, all rights reserved. Original articles and site content may not be reproduced from our site without consent from superdotnet.com.
Privacy Policy and User Site Agreement