Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)

IOTA^_^    

Sams Teach Yourself ASP.NET in 21 Days, Second Edition

By Chris Payne

Table of Contents
Appendix A.  Answers to Quiz Questions

Quiz

1:

What is a proxy class?

A1:

A class that provides methods for a client application to access a Web Service's methods. You use the proxy class because it provides built-in support for sending and receiving XML messages.

2:

Write an example of a typical use of the disco.exe tool.

A1:

disco http://localhost/tyaspnet21days/services.disco

3:

Write an example of a typical use of the wsdl.exe tool.

A1:

wsdl /language:VB http://localhost/tyaspnet21days/day16/Calculator.asmx?WSDL

4:

True or false: Discovery must be performed before proxy generation.

A1:

False. Discovery isn't a necessary step.

5:

Which two namespaces are required for using SOAP headers to access services?

A1:

System.Web.Services and System.Web.Services.Protocols.

6:

Create a simple SOAP header class. What do you do with this class in a Web method? On the client?

A1:

1: Public Class SOAPHeader : Inherits SoapHeader 2: Public Username as string 3: Public Password as string 4: End Class

You need to create an instance of this class in any class that you want to expose as a service. The Web methods that use this class must specify the attribute <SoapHeader()>.

The client must create an instance of the class as well (through the proxy), and set its properties.

Exercise

Q1:

Generate a proxy class for the ConvertUnits service you created in exercise 2 on Day 16. Build an interface to allow users to enter values.

A1:

First create a proxy with the following command:

wsdl /l:VB /namespace:TYASPNET.Clients http://localhost/tyaspnet21days/day16/ConvertUnits.asmx?WSDL

Compile the proxy with the following command:

vbc /t:library /out:..\..\bin\TYASPNET.Clients.ConvertUnits.dll /r:System.dll /r:System.Data.dll /r:System.Web.dll /r:System.Web.Services.dll /r:System.Xml.dll ConvertUnits.vb

Then build the ASP.NET page:

1: <%@ Page Language="VB" %> 2: 3: <script runat="server"> 4: sub Submit(Sender as Object, e as EventArgs) 5: dim objService as new TYASPNET.Clients.ConvertUnits 6: dim dblResult as double 7: 8: dblResult = objService.Convert(tbValue.Text, _ 9: lbUnitsFrom.SelectedItem.Text, _ 10: lbUnitsTo.SelectedItem.Text) 11: 12: lblMessage.Text = tbValue.Text & " " & _ 13: lbUnitsFrom.SelectedItem.Text & " = " & _ 14: dblResult & " " & lbUnitsTo.SelectedItem.Text 15: end sub 16: </script> 17: 18: <html><body> 19: <form runat="server"> 20: Convert: 21: <asp:TextBox runat="server" /> 22: <asp:ListBox runat="server" 23: Size="1"> 24: <asp:ListItem>mm</asp:ListItem> 25: <asp:ListItem>cm</asp:ListItem> 26: <asp:ListItem>m</asp:ListItem> 27: <asp:ListItem>km</asp:ListItem> 28: <asp:ListItem>in</asp:ListItem> 29: <asp:ListItem>ft</asp:ListItem> 30: <asp:ListItem>yd</asp:ListItem> 31: <asp:ListItem>mi</asp:ListItem> 32: </asp:ListBox> 33: to: 34: <asp:ListBox runat="server" 35: Size="1"> 36: <asp:ListItem>mm</asp:ListItem> 37: <asp:ListItem>cm</asp:ListItem> 38: <asp:ListItem>m</asp:ListItem> 39: <asp:ListItem>km</asp:ListItem> 40: <asp:ListItem>in</asp:ListItem> 41: <asp:ListItem>ft</asp:ListItem> 42: <asp:ListItem>yd</asp:ListItem> 43: <asp:ListItem>mi</asp:ListItem> 44: </asp:ListBox><p> 45: 46: <asp:Button runat="server" 47: Text="Submit" 48: OnClick="Submit" /><p> 49: <asp:Label runat="server" /> 50: </form> 51: </body></html>


    IOTA^_^    
    Top

    Категории