Workshop

for RuBoard

This workshop will help reinforce the concepts covered in today's lesson.

Quiz

1:

Why is SOAP important?

A1:

SOAP provides a standard XML grammar that a client and server can agree on to exchange XML messages so that the client can invoke operations on the server. It is both language and platform independent and has wide reach because of the ubiquity of HTTP and XML.

2:

How should you architect the methods of your Web service?

A2:

You can think of a Web service as simply an extension of the presentation services tier, albeit a programmatic rather than a graphical one, so it should be designed to utilize your data services tier . In this way, you get the benefit of code reuse and abstraction, which, combined with the simple programming model provided by ASP.NET, makes implementing a Web service fairly simple.

3:

How does VS .NET allow a Web service to be called?

A3:

When adding a Web reference to the ASP.NET project, VS .NET downloads the WSDL document from the Web service and creates a proxy class in the project that can be used to call the methods of the Web service as if they were exposed in any other managed class. The proxy class also supports asynchronous execution of the methods and can be used to dynamically change the end point of the Web service through the Url property.

4:

What techniques can you use for consuming a Web service in an ASP.NET application?

A4:

One particularly effective technique for calling a Web service from an ASP.NET page is to encapsulate the code to call it in a Web User Control. Using this approach, the data from the Web service can be reused on several pages. More importantly, you can take advantage of ASP.NET page output caching. By using output caching, you can decrease the number of calls to the Web service because the output from the first call can be cached. You can also set the duration the output will be saved in the cache as well as whether the cache will contain multiple copies for different browsers or query strings.

Exercise

Q1:

Write a method that would extend the Catalog Web service by allowing a client to retrieve all the details for a particular book.

A1:

One possible solution to the exercise is as follows .

First, to provide the Web service with the appropriate methods, the data services tier would need to be extended to support it. This means that the WebData class shown in Listing 19.1 would need to include a method such as TitleInfo that gets the information for a particular ISBN like so:

 Public Function TitleInfo(ByVal isbn As String) As DataSet   Dim ds As New DataSet("Titles")   Dim dt As DataTable   Dim parms As New HybridDictionary()   parms.Add("isbn", isbn)   Try     ds = MyBase.Factory.GetDataSet("GetTitles", parms)     ds.Tables(0).TableName = "Title"     ds.Namespace = "www.computebooks.com"     ds.Prefix = "cbks"     Return ds   Catch e As Exception     MyBase.ThrowComputeBookException("TitleInfo operation failed", e)   End Try End Function 

Note that this method relies on the DataFactory class exposed through its base class and a GetTitles.config file would need to exist on the Web server. Next, the Web service would simply expose a GetBook method that would call the method in the WebData class as follows:

 [WebMethod(Description="Retrieves all the information for a particular ISBN",   EnableSession=false)] public DataSet GetBook(string isbn) {    DataSet books;    // Read the configuration information    string connect = ConfigurationSettings.AppSettings["SqlConnect"].ToString();    string provider = ConfigurationSettings.AppSettings["Provider"].ToString();    // Instantiate the data access class and call the method    WebData data = new WebData(connect,provider,      new DirectoryInfo(this.Server.MapPath("bin")));    books = data.TitleInfo(isbn);    return books; } 
for RuBoard


Sams Teach Yourself Ado. Net in 21 Days
Sams Teach Yourself ADO.NET in 21 Days
ISBN: 0672323869
EAN: 2147483647
Year: 2002
Pages: 158
Authors: Dan Fox

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