|
Create an HTML Client
To create an HTML client to consume a Web service you can reuse the existing Mobile Web Form application project from my last article. Here's the link to download the project files. These are the steps to load the project in Visual Studio .NET. You may need to adjust the paths and drive letters shown below.
- Extract the zipped files to the wwwroot directory. After extracting the files you will have a new directory called c:\inetpub\wwwroot\Stock_Clients.
- Mark the Stock_Clients directory as a virtual directory in IIS.
- Open the C# project file in Visual Studio. (Select "File> Open> Project" from the File menu and navigate to the c:\inetpub\wwwroot\Stock_Clients).
- Set the Web Form MobileWebForm1.aspx as the start page. To do that, right-click on the file name in the Solution Explorer window and select the "Set as Start Page" item from the context menu.
- Build the project by clicking on the "Build" menu and selecting "Build All" or "Build" menu item.
- Run the application in debug mode. (Use the "Debug" icon on the tool bar) . If you haven't installed the MS Mobile Internet Tool Kit you will get an error. You can ignore this error for the HTML client. This procedure is not meant to be a complete explanation of the client, it merely saves time by reusing the existing project from the previous article rather than creating a new project and proxy objects.
Create a Web Form for the HTML Client
- Add a new Web Form to the existing project (Right click on the project name on the "Solution Explorer" window and select "Add> Add Web Form" from the context menu. Name the new Web Form "HTML_WebForm.aspx".
- Create a Web interface by dragging and dropping web HTML controls from the tool box. The Web form should look like Figure 1.
- Write the code to activate the "Get Quote" and "New Quote" buttons.
private void Btn_Get_Quote_Click(object sender,
System.EventArgs e)
{
netxmethodsservicesstockquoteStockQuoteService
proxyClass = new
netxmethodsservicesstockquoteStockQuoteService();
try
{
if (proxyClass.getQuote(Txt_Code.Text).
ToString() != "-1")
Lbl_Price.Text = "Price :- $" +
proxyClass.getQuote
(Txt_Code.Text).ToString();
else
Lbl_Price.Text = "Stock code not found";
}
catch
{
Lbl_Price.Text = "Stock code not found";
}
}
private void Btn_New_Quote_Click(object sender,
System.EventArgs e)
{
Lbl_Price.Text = "";
Txt_Code.Text = "";
}
Sometimes the Java based GLUE Stock quotes service hangs when you enter an invalid stock code. It also returns -1 when it doesn't recognize the stock code. When accessing Web services, you should plan for both exceptions. Therefore, the code uses some exception handling (the try and catch blocks in the preceding C# code listing). The core of the code is very similar to the WAP client in the last article.
- Build the project, and then run the project in debug mode. Running the project launches your browser and requests the HTML_WebForm.aspx page automatically. The result looks like Figure 2.
|
|
 |
TALK
BACK |
|
What are you using to create web pages to consume XML Web Services? Are you simultaneously building WAP and Windows clients? Are you using Java to build Web services as well as .NET?
|
|
|
|
|
|
|