ASP.NET Logo Back to WebMatrix Home

 
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.
  1. Open Microsoft ASP.NET Web Matrix.  You will see the New File dialog box appear.
  2. Select (General) from the Templates pane.
  3. Select the ASP.NET Page template.
  4. Type a file path in the Location box.
  5. Type myFirstWSClient.aspx in the Filename box.
  6. Select Visual Basic in the Language drop-down box.
  7. Click OK. The myFirstWSClient.aspx file will open in Design view. 

    New File Dialog

  8. 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 

    Add Controls

  9. Select the Code tab.

     
  10. Choose WebService Proxy Generator menu item from the Tools menu.

     
  11. You will see the XML Web Service Proxy Generator dialog box appear.

    WS Proxy Dialog

  12. 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

     

  13. Type MatrixDemo in the Namespace box.

     
  14. Select Visual Basic .NET in the Language drop-down box.

     
  15. 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.

     

     

  16. Accept the default values for Source File and Generate Assembly boxes.

     
  17. Click Generate

     
  18. You will see a message box confirming the successful generation of the Web service proxy.

    WS Proxy Confirm Dialog

  19. Click OK

     
  20. Click Cancel to close the XML Web Service Proxy Generator dialog box.

     
  21. 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.

     
  22. 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
  23. Save and run the ASP.NET page.

     
  24. Your ASP.NET page will automatically appear in a new instance of your Web browser.

     
  25. Click the Button.

     
  26. The DataGrid will show all of the rows in the Orders table. 

    Web Service DataGrid

  27. Close the Web browser instance.

Next Step >>