Implementing an ASP.NET Client


The same service now can be used from an ASP.NET Client application. Referencing the Web service can be done the same way as with the Windows application.

Try It Out – Creating an ASP.NET Client Application

image from book
  1. Create a new C# ASP.NET Website, call it ASPNETClient, and add two text boxes and a button to the Web form, as shown in Figure 20-17.

    image from book
    Figure 20-17

  2. Add a Web reference to http://localhost/webservicesample/service.asmx in the same way you did with the Windows application.

  3. With the Web reference added, a client proxy class was again generated. Add a click handler to the button and write the following lines of code for this handler:

    private void Button1_Click(object sender, System.EventArgs e) { WebServicesSample.Service ws = new WebServicesSample.Service(); TextBox2.Text = ws.ReverseString(TextBox1.Text); } 

  4. Now build the project and with Debug Start, you can start the browser and enter a test message in the first text box. When you press the button, the Web service is invoked, and you get the reversed message returned in the second text box, as shown in Figure 20-18. With a multi- project solution, you have to set the startup project to the project you want started.

    image from book
    Figure 20-18

image from book

As you have just seen, using Web services is as easy in Web applications as it is in Windows applications!




Beginning Visual C# 2005
Beginning Visual C#supAND#174;/sup 2005
ISBN: B000N7ETVG
EAN: N/A
Year: 2005
Pages: 278

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net