214 IBM WebSphere Everyplace Access V5, Volume II: Application Development
Figure 7-8 Importing the provided Java file
7. If a package error appears, include the following statement at the beginning of
the Primes.java file, located in the /JavaSource/primes/ folder:
package primes;
7.2.1 A sample Web Service
In this section of the sample scenario, you will review the Primes.java code. For
example, to view the source code to
Primes.java, double-click the file name. This
file is located in the /Java Source/primes/ folder.
򐂰 The only important method for you in this code is the getPrime() method. This
method receive a number of digits and returns a prime number with the
specified length of digits.
Chapter 7. Accessing Web Services 215
򐂰 When executing this method, try generating prime numbers of 20 or fewer
digits to avoid long computations. A short version of the prime number
generator is shown in Example 7-1.
Example 7-1 Primes.java - getPrime() method
package primes;
import java.math.BigInteger;
import java.util.Vector;
public class Primes {
private static final BigInteger ZERO = new BigInteger("0");
private static final BigInteger ONE = new BigInteger("1");
private static final BigInteger TWO = new BigInteger("2");
private String prime = "";
......
......
......
public static String getPrime(int numDigits) {
BigInteger start = random(numDigits);
start = nextPrime(start);
return start.toString();
}
}
Creating a Web Service
In this section, you create a Web Service in the PrimesWebService project that
you just created. You will use the wizards provided by WebSphere Studio Site
Developer to do this. Once created, the Web Service will be published and
invoked to be executed in a WebSphere Test Environment.
1. Select File -> New -> Other.
216 IBM WebSphere Everyplace Access V5, Volume II: Application Development
Figure 7-9 Starting creation of Portlet project
2. Select Web Services -> Web Service and click Next.
Chapter 7. Accessing Web Services 217
Figure 7-10 Selection of Web Service
3. Enter the following information in the Web Services window:
a. Web Service type: Java bean Web Service.
b. Check the box Start Web service in Web project.
c. Check the box Generate a proxy.
d. Client proxy type: Java proxy.
e. Check the box Test the generate proxy.
Click Next.
218 IBM WebSphere Everyplace Access V5, Volume II: Application Development
Figure 7-11 Web Service wizard
4. In Service Deployment Configuration, click Edit in Server-Side Deployment
Selection section and select the following:
Server: Server Types
WebSphere version 5.0 WebSphere v5.0 Test
Environment
Web service runtime: IBM WebSphere V5.
Service Web Project: PrimesWebService.
Click OK.

Get IBM WebSphere Everyplace Access V5 Handbook for Developers and Administrators Volume II: Application Development now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.