> developer > dnu > courses > Web Services page 18
Web Services
April 2003
DeveloperNet University Course
Reader Rating    from ratings rate this article
View an eBook Version of this course - LARGE FILE! Send this page to a friend

Exercise 8: Build a Consumer Weather Service

  1. Create objects to use an existing web service. Since we are only going to Consume a Web Service we only need produce the Client and the Stubs that the client will use to connect jBroker Web to connect to the Web Services.

    1. From the File menu, select New or click

    2. From the New File window, select the Web Services tab. Select Existing WebService. Click OK.

    3. In the Web Service Wizard window, type the following URL into WSDL file or URL to use: URL http://www.xmethods.net/sd/TemperatureService.wsdl. Click Next.

    • In the next window, supply the following information

    • Use the default for the "Root directory for generated objects".

    • Leave Generate stubs checked and check Verbose mode.

    • Type temp in Specify package for generated files.

    • Click Finish.

    1. The workbench created stubs and a test client file. Double click on the test client file called Temperature_CLIENT.java in the WebServices\src\temp directory.

    2. Un-comment the println() method and replace the java.lang.String entry with args[0]. This will allow you to enter any zip code on the command line, and have the service return the current temperature in that area.

    3. System.out.println("Test Result = " + remote.getTemp(args[0]));

    4. Save

    5. Compile by running the Build and archive command.

  2. Test your client

    1. From the Project menu select Run Web Service Client Class.

    2. Select temp.Temperature_CLIENT as the Client Class to run. Enter the a zip code, such as 01821, into the Arguments field. Click Run.

    3. The result should be similar to the following:

Web Service Wizard Client Runner.

Figure 5: Web Service Wizard Client Runner.


Temperature_CLIENT.java
// The following code was generated within the Novell exteNd Workbench
// using the integrated Web Services Wizard. This code *requires* process() method
// modification in order to execute as expected. Please keep in mind when making
// modifications that method implementations must be consistent across all
// generated objects.
//

package temp;

import javax.naming.*;

public class Temperature_CLIENT
{
public void process(String[] args) throws Exception
{
Temperature remote = getRemote(args);

// The following code has been generated for your testing convenience. In
// order to successfully test your Web Service, you must uncomment one or
// more of these lines and supply meaningful arguments where necessary.
// Once you have modified the test method(s) below, compile this class and
// execute it from a command line with your class path set appropriately.

System.out.println("Test Result = " + remote.getTemp(args[0]));
}

public Temperature getRemote(String[] args) throws NamingException
{
String lookup = "xmlrpc:soap:temp.Temperature";
InitialContext ctx = new InitialContext();
return (Temperature)ctx.lookup(lookup);
}

public static void main(String[] args)
{
try
{
Temperature_CLIENT client = new Temperature_CLIENT();
client.process(args);
}
catch (Exception _e)
{
System.out.println("*** Error Executing Generated Test Client ***");
_e.printStackTrace();
}
}
}

Previous Contents Next
download sample file