|
|

|
 |
 |
 |
|
|
 |
| Web Services |
 |
| April 2003 |
 |
| DeveloperNet University Course |
 |
 |
| Reader Rating |
 |
|
 |
from ratings |
 |
|
 |
|
|
Exercise 8: Build a Consumer Weather Service
- 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.
- From the File menu, select New or click
- From the New File window, select the Web Services tab. Select Existing WebService. Click OK.
- 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.
- 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.
- 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.
- System.out.println("Test Result = " + remote.getTemp(args[0]));
- Save
- Compile by running the Build and archive command.
- Test your client
- From the Project menu select Run Web Service Client Class.
- Select temp.Temperature_CLIENT as the Client Class to run. Enter the a zip code, such as 01821, into the Arguments field. Click Run.
- The result should be similar to the following:
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(); } } }
|
 |
 |
 |