Answers for Day 16

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's a Web service?

A1:

It's a piece of functionality that's accessible over the Internet via standard protocols such as XML and HTTP.

2:

What does SOAP stand for, and what does it do?

A1:

The Simple Object Access Protocol is a way for Web services to communicate with clients. It's based on XML.

3:

What's a service description?

A1:

It's an XML file that tells clients what a Web service does and what types of data it expects and returns.

4:

What class (including namespace) must a Web service inherit from?

A1:

 System.Web.Services.WebService 
5:

Write an arbitrary Web method that enables caching and disables session state.

A1:

 <WebMethod(CacheDuration=60, EnableSession=False)> public function HelloWorld() as String    Return "Hello World!" end function 
6:

True or false: A Web method can take advantage of intrinsic ASP.NET objects, such as Session and cache.

A1:

True.

7:

True or false: A Web method can return a DataSet.

A1:

True. A DataSet is internally represented by ADO.NET as XML, so it's easy to transport the data to a client as XML.

Exercises

1:

Examine the XML service description for the database service you created earlier today. Try to understand each of the tags, recalling the discussions on XML and XML schemas. Note that much of the file describes how the different protocols (Http-Get, SOAP, and so on) are to send and receive data.

2:

Create a Web service that converts one unit of measurement into another. This method should take three parameters: a value, a unit to convert from, and a unit to convert to. Allow the user to convert to and from the following: millimeters, centimeters, inches, feet, meters, yards, miles, and kilometers. Don't forget to test it with the HTML Description page!

(Don't worry if you don't know the exact conversions between units of measurement. Just make something up.)

A1:

 1:    <%@ WebService Language="VB"  %> 2: 3:    Imports System 4:    Imports System.Web.Services 5: 6:    public Class ConvertUnits : Inherits WebService 7: 8:       '******************************************************* 9:       ' Convert: Assumes that the incoming value is of unit 10:       ' millimeter, and converts to strTo. 11:       ' Then passes converted value to ConvertTo function, 12:       ' which corrects for the unit that was actually passed in 13:       ' ie dblValue=10, strFrom=yd, strTo=in, 14:       ' answer = 10mm=>inches = 10/25.4 = .394 inches 15:       '******************************************************* 16:       <WebMethod(Description:="Converts " & _ 17:          "values to and from a specified unit of measure", _ 18:    EnableSession:=false)> Public Function Convert(dblValue As Double, _ 19:          strFrom as String, strTo as String) As Double 20: 21:          select case strTo 22:             case "mm" 23:                Return ConvertTo(dblValue/1, strFrom) 24:             case "cm" 25:                Return ConvertTo(dblValue/10, strFrom) 26:             case "in" 27:                Return ConvertTo(dblValue/25.4, strFrom) 28:             case "ft" 29:                Return ConvertTo(dblValue/304.8, strFrom) 30:             case "m" 31:                Return ConvertTo(dblValue/1000, strFrom) 32:             case "yd" 33:                Return ConvertTo(dblValue/914.4, strFrom) 34:             case "mi" 35:                Return ConvertTo(dblValue/1609344, strFrom) 36:             case "km" 37:                Return ConvertTo(dblValue/1000000, strFrom) 38:             case else 39:                return 0.0 40:         end select 41:       End Function 42: 43:       '******************************************************* 44:       ' ConvertTo: Receives a value from Convert, and adjusts 45:       ' for strFrom. 46:       ' We can do this because Convert assumed that incoming 47:       ' value was millimeter, so we can just alter the value 48:       ' depending on what the incoming unit actually was 49:       ' ie dblValue=26.7, strFrom=cm, 50:       ' answer = cm=>mm = 26.7*10 = 267 51:       ' try it, it really does work! 52:       '******************************************************* 53:       Private Function ConvertTo(dblValue as double, _ 54:          strFrom as string) as double 55: 56:          Select case strFrom 57:             case "mm" 58:                return dblValue * 1 59:             case "cm" 60:                return dblValue * 10 61:             case "in" 62:                return dblValue * 25.4 63:             case "ft" 64:                return dblValue * 304.8 65:             case "m" 66:                return dblValue * 1000 67:             case "yd" 68:                return dblValue * 914.4 69:             case "mi" 70:                return dblValue * 1609344 71:             case "km" 72:                return dblValue * 1000000 73:             case else 74:                return 0.0 75:          End Select 76:       End Function 77: 78:    End Class 


    IOTA^_^    
    Top


    Sams Teach Yourself ASP. NET in 21 Days
    Sams Teach Yourself ASP.NET in 21 Days (2nd Edition)
    ISBN: 0672324458
    EAN: 2147483647
    Year: 2003
    Pages: 307
    Authors: Chris Payne

    Similar book on Amazon

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