CSCI E-143 CertPrep:   Web Services   (Kalani, chapter 7)

Saturday, Dec. 18, 2004

This Saturday we cover Kalani's chapter 7, "Web Services".   This is a very short chapter.   In fact,  the part you are actually responsible for is shorter than the chapter itself,  because Kalani briefly shows how to set up a web service,  and for this test,  you only have to know how to use a web service,  not how to write one.   Nevertheless,  some tricky questions might come up.

Terms

A Web Service is a program that exposes is methods for use over the internet.   It differs from a "web app" because it does not return a web page.   It returns its output in a coded form for use by your Windows client.   You must have a Windows client to pass data to the web service and to display the output you receive from it.

A Web Method is a routine in a web service that you can invoke across the internet.   (A web service class may of course have its own private methods not exposed to web access.)

SOAP.   Simple Object Access Protocol.   Encapsulates object calls as XML.   Used in passing data both ways between a Windows client and the web service it uses.

Discovery is finding out about web services:  where they are,  the names of the classes,  and the names and natures of the web methods they expose.

Disco.   A command-line web services discovery tool used by Microsoft.

UDDI.   Universal Description,  Discovery,  and Integration.   Another web services tool,  also involving a registry.   But there is no  .uddi  file extension.

WSDL.   Web Services Description Language.   Tells the SOAP message types possible for this service.   In addition, .wsdl  is a file extension for a file containing such information,  which might be produced by the various tools for discovering web services.


Creating a Web Service

You will not be asked about creating a web service on this exam.   (It is covered on exam 70-320.)   But it may clarify things if we do a simple example.     (Kalani, pp. 575-576)

Instantiating and Invoking Web Services from a Windows Application

Some of this might be on the exam.

There are two ways to do this:  the hard way and the easy way.

The Hard Way:   Using  disco.exe  and  wsdl.exe

Some command-line options for  wsdl.exe

The Easy Way:   Using Web References       (Kalani, pp. 572-573)

There is another advantage to doing it this easy way:  if the web service changes,  you can get updated information by right-clicking the Web reference node in Solution Explorer and selecting  "Update Web Reference".


Asynchronous Web Service Calls       (Kalani, pp. 591-592)

Kalani gives this useful example at the end of the chapter.   It uses a callback method which is invoked when the called web service returns with the information for the local program to display.

The important thing about this code is that it makes no reference to the web service that is not already made for a synchronous method.   That is,  such asynchronous calls require no coding on the server end.

Here is the code:       (Kalani, p. 593)

private void btnGetWeather_Click(object sender, System.EventArgs e)
{
  // Declare the Web service main object

  com.capescience.live.AirportWeather aw =
    new com.capescience.live.AirportWeather();

  // Invoke the Web service. This may take some time, so call it asynchronously.
  // First, create a callback method.

  AsyncCallback wcb = new AsyncCallback(WebServiceCallback);

  // And then initiate the asynchronous call.
  // "BegingetSummary" is in the proxy class.

  aw.BegingetSummary(txtCode.Text, wcb, aw);
}

// This method will get called when the Web service call is done.

public void WebServiceCallback(IAsyncResult ar)
{
  // Retrieve the state of the proxy object.

  com.capescience.live.AirportWeather aw = 
    (com.capescience.live.AirportWeather)ar.AsyncState;

  // Call the End method to finish processing.
  // "EndgetSummary" is in the proxy class.

  com.capescience.live.WeatherSummary ws = aw.EndgetSummary(ar);

  // Display the results.

  lbResults.Items.Clear();
  lbResults.Items.Add(ws.location);
  lbResults.Items.Add(“Wind “ + ws.wind);     //etc., etc., etc.
}

Here are the relevant questions from the two tests at the end of the "short Kalani"  book:  

    Test 1:  questions  36  (page 373;  answer:  page 395),  37.

    Test 2:  questions  23  (page 415;  answer:  page 443),  24,  25.

(Some of these questions may duplicate those in long Kalani.   Both texts are listed here.)


Last  revised  Dec. 17, 2004