Listing 1 Compiler directives

<%@ Page language="C#" Inherits=
"System.Web.UI.MobileControls.MobilePage"%>
<%@ Register TagPrefix="mobile" Namespace=
"System.Web.UI.MobileControls" Assembly=
"System.Web.Mobile" %>

Listing 2 Server-side controls

<mobile:form id="Form1" runat="server">
<mobile:TextBox id="TextBox1" runat="server"
Text="This is Form1." />
<mobile:Command id="Button1"
onclick="ButtonRoutine"
runat="server" text="Go!"></mobile:Command>
</mobile:form>
<mobile:form id="Form2" runat="server">
<mobile:TextBox id="TextBox2" runat="server"
Text="This is Form2." />
</mobile:form>

Listing 3 Server-side script

<script runat="server">
void ButtonRoutine(object system,
System.EventArgs e) {
ActiveForm = Form2;
}
</script>

Listing 4 AreaWeatherWS.asmx

<%@ WebService Language="VB"
Class="AreaWeatherWS" %>
Imports System
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Serialization

'This class makes a request to wunderground.com
'and retrieves weather information based on a
'postal code or area name
<WebService(Description:="Sojourner Web Service",_
Namespace:="http://localhost/Sojourner/")>_
Public Class AreaWeatherWS
Inherits System.Web.Services.Protocols.
HttpGetClientProtocol
Public Sub New()
MyBase.New
Me.Url = "http://www.wunderground.com/cgi-bin/
findweather/getForecast"
End Sub
<WebMethod(),_
HttpMethodAttribute(GetType(TextReturnReader),
GetType(UrlParameterWriter))> _
Public Function GetWeather(ByVal query As String)
As GetWeatherMatch
Return CType(Me.Invoke("GetWeather", _
(Me.Url), New Object() {query}), _
GetWeatherMatch)
End Function
End Class

'This class uses regular expressions to find
‘specific text within the HTML source and
‘will return it as a string
Public Class GetWeatherMatch
<MatchAttribute(
"<tr ><td>Temperature</td>\n<td><b>(.*)
<tr ><td>Moon Phase</td><td>",
IgnoreCase:=true)> _
Public Weather As String
End Class

Listing 5 ProxyCompiler.bat

path=c:\program files\Microsoft.NET\FrameworkSDK\bin;
c:\winnt\Microsoft.NET\Framework\v1.0.2914
wsdl.exe
http://localhost/Sojourner/AreaWeatherWS.asmx?wsdl
/l:vb /n:AreaWeatherWS
vbc /out:/bin/AreaWeatherWS.dll /t:library /r:System.dll
/r:System.Xml.dll /r:System.Web.Services.dll
AreaWeatherWS.vb

Listing 6 SojournerMobilePage.aspx <%@ Register TagPrefix="mobile" Namespace=
"System.Web.UI.MobileControls" Assembly=
"System.Web.Mobile" %>
<%@ Page language="C#" Inherits=
"System.Web.UI.MobileControls.MobilePage" %>
<%@ Import Namespace="AreaWeatherWS"%>
<mobile:form id="frmMain" runat="server">
<mobile:Label id="lblMainCaption" runat="server" Text=
"SOJOURNER" /><br>
<mobile:Label id="lblPrompt" runat="server"
Text="Please enter postal code
or country name" />
<br>
<mobile:TextBox id="txtEntry" runat="server" />
<br>
<mobile:Command id="btnGo" onclick="ViewWeather"
runat="server" text="Go!" />
</mobile:form>
<mobile:form id="frmWeatherData" runat="server">
<mobile:Label id="lblWeather" runat="server" />
<mobile:Command id="btnBack"
onclick="ReturnToMain"
runat="server" text="Back" />
</mobile:form>
<script runat="server">
void ReturnToMain(object sender, System.EventArgs e)
{
ActiveForm = frmMain;
}
void ViewWeather(object sender, System.EventArgs e)
{
AreaWeatherWS WeatherWebService =
new AreaWeatherWS();
GetWeatherMatch match;
match =
WeatherWebService.GetWeather(txtEntry.Text);
string WeatherResults = match.Weather;
WeatherResults =
Regex.Replace(WeatherResults,"°","");
WeatherResults =
Regex.Replace(WeatherResults,"<td>","");
WeatherResults =
Regex.Replace(WeatherResults,
"</td></tr>","...");
WeatherResults =
Regex.Replace(WeatherResults,"<tr >","");
WeatherResults =
Regex.Replace(WeatherResults,"</td>","");
WeatherResults =
Regex.Replace(WeatherResults,"<b>","");
WeatherResults =
Regex.Replace(WeatherResults,"<BR>","");
WeatherResults =
Regex.Replace(WeatherResults,"<br>","");
WeatherResults =
Regex.Replace(WeatherResults,"</B>","");
WeatherResults =
Regex.Replace(WeatherResults,"<","<");
WeatherResults =
Regex.Replace(WeatherResults,">",">");
WeatherResults = "Temperature " + Regex.Replace
(WeatherResults,"</b>","");
lblWeather.Text = WeatherResults;
ActiveForm = frmWeatherData;
}
</script>