| |
| XML Web Services |
| Create a Web service client |
In this walkthrough, you will generate an
XML Web service proxy class and use it from an ASP.NET page to
call the XML Web service you developed in the previous walkthrough.
This XML Web Service could live on any remote server -- providing a powerful
and easy way to distribute code and data across a network.
- Open Microsoft ASP.NET Web Matrix. You will see the New
File dialog box appear.
- Select (General) from the Templates pane.
- Select the ASP.NET Page template.
- Type a file path in the Location box.
- Type myFirstWSClient.aspx in the Filename box.
- Select Visual Basic in the Language drop-down box.
- Click OK. The myFirstWSClient.aspx file will open in
Design view.
- From the Web Controls tab in the Toolbox, drag a
DataGrid control and a Button control onto the ASP.NET page.
Press the Enter key between the placement of each control
- Select the Code tab.
- Choose WebService Proxy Generator menu item from the Tools
menu.
- You will see the XML Web Service Proxy Generator dialog box
appear.
- Type the name of the fully qualified URL for the Web service you
developed earlier in this section in the WSDL URL box. For example:
http://localhost:8080/myFirstWebService.asmx
Note WSDL is an acronym for Web Services Description Language.
WSDL defines how an XML Web service behaves and instructs clients as to
how to interact with the service. You can access the WSDL for a Web
service by appending a WSDL query string parameter to a Web service URL.
For example: http://localhost:8080/myFirstWebService.asmx?WSDL
- Type MatrixDemo in the Namespace box.
- Select Visual Basic .NET in the Language drop-down box.
- Type a file path in the Output Directory box.
Important ASP.NET Web Matrix requires that proxy files reside in
the same file path as the calling ASP.NET page.
- Accept the default values for Source File and Generate
Assembly boxes.
- Click Generate.
- You will see a message box confirming the successful generation of the
Web service proxy.
- Click OK.
- Click Cancel to close the XML Web Service Proxy Generator
dialog box.
- Select the Design tab and double-click the Button
control. ASP.NET Web Matrix will automatically wire-up an event handler
for the Button control's Click event and open the page in Code
view.
- Add code to the Button1_Click event that calls the Web Service Proxy
object just generated and binds the results of calling the GetOrders
WebMethod to the DataGrid:
Sub Button1_Click(sender As Object, e As EventArgs)
'Declaration format: Dim variablename As New Namespace.Class
Dim wsProxy As New MatrixDemo.Sample()
DataGrid1.DataSource = wsProxy.GetOrders()
DataGrid1.DataBind()
End Sub
- Save and run the ASP.NET page.
- Your ASP.NET page will automatically appear in a new instance of your
Web browser.
- Click the Button.
- The DataGrid will show all of the rows in the Orders
table.
- Close the Web browser instance.
Next Step >> |
|