Web interface using ASP.NET
First we have to define the layout of the web page in an aspx file,
for example:
/csbook/solutions/19/BookStore.aspx
<%@ Page language="C#" Inherits="BookStorePage" src="BookStore.aspx.cs" %>
<html>
<body>
<form Runat="server">
<asp:TextBox ID="isbn" Runat="server"/>
<asp:Button ID ="search" Text="Search" OnClick="Search" Runat="server"/>
<hr>
<table border="0">
<tr>
<td>Author:</td>
<td><asp:Label id="author" Runat="server"/>
</tr>
<tr>
<td>Title:</td>
<td><asp:Label id="title" Runat="server"/>
</tr>
<tr>
<td>Price:</td>
<td><asp:Label id="price" Runat="server"/>
</tr>
</table>
</form>
</body>
</html>
|
The program logic is implemented in a code-behind file, for example:
/csbook/solutions/19/BookStore.aspx.cs
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class BookStorePage: Page {
protected TextBox isbn;
protected Button search;
protected Label author;
protected Label title;
protected Label price;
public void Search(object sender, EventArgs e) {
BookStoreService store = new BookStoreService();
if (store.Available(isbn.Text)) {
author.Text = store.Author(isbn.Text);
title.Text = store.Title(isbn.Text);
price.Text = store.Price(isbn.Text).ToString() + " Euro";
} else {
author.Text = title.Text = price.Text = "";
}
}
}
|
Because the code-behind accesses the web service BookStoreService from
exercise 2 we must generate a proxy class (using wsdl.exe as described there).
wsdl /out:BookStoreService.cs http://dotnet.jku.at/csbook/solutions/19/BookStoreService.asmx?WSDL
This class must be compiled into a DLL that we have to store in the subdirectory
bin of our virtual directory:
csc /target:library /out:bin\BookStoreService.dll BookStoreService.cs
Now we can point a web browser to our aspx file, for example:
http://dotnet.jku.at/csbook/solutions/19/BookStore.aspx
and see the web page that we created.
|