C H A P T E R  16

Tutorial--Section 4.1
Prepare to Create a Web Service Model

This chapter describes how to expand the application to access data via a Web service. You must be running a version of the Suntrademark ONE Studio that includes the Web service model wizard. You must also have a connection to the Internet without a proxy/firewall which will interfere with communication to the Web service.

You can expand the existing application by adding a Web service-based model and a page to display that model's data. First, there are some resources you need to download to build a model for a Web service, and you need to register as a user for this Web service.


Task 1: Web Service User Registration and Downloading

Download the Web Service SDK

Download the Google Web service software SDK that contains the WSDL file that the Suntrademark ONE Application Framework needs to create the Web Service model.

1. To download the Google Web Service SDK, go to http://www.google.com/apis/download.html

2. Accept the agreement.

3. Click the Download button.

4. Save the file on your hard drive.

Open the zip file and extract the googleapi/GoogleSearch.wsdl file to your application's lib directory (.../JatoTutorial/WEB-INF/lib). There are three versions of this file in the zip file. Be sure to get the only one that is not under the dotnet directory. That is all you need to build the Web service model.



Note - When you copy a new file into your applications file structure, occasionally it takes the Sun ONE Studio some time to refresh its state.

If it appears that the Sun ONE Studio is taking too long to recognize the new file, you can go to the Filesystems or Project tab, right-click the lib directory, and select the Refresh Folder action.



Register to Use the Web Service

To use the Google Web service, you must register as a user to receive a key that is passed to the Web service with each query.

1. To register with Google, go to

https://www.google.com/accounts/NewAccount?continue=http://api.google.com/createkey&followup=http://api.google.com/createkey

2. Enter an email address and password to register a new account.

You will receive an email to verify your account. Once you verify your account, you will receive another email with your key (it is a long string of letters and numbers). Keep this email handy because you will need it when you create the Web service model.

Create the Web Service Model

Using the WSDL file, you will create a Web service model that will perform an Internet search using the Google Internet search engine via their Web service.

1. Select the main module folder.

2. Click the Add Model button on the Sun ONE Application Framework toolbar.

The Select Model Type panel displays.

This figure shows the Select Model Type panel. 

3. Enter GoogleSearchModel in the Model name textbox.

4. Select Web Service Model from the model component list.

5. Click Next.

The Select Local WSDL File panel displays.

This figure shows the Select Local WSDL File panel. 

Navigate down the JatoTutorial application directory structure to the lib directory (JatoTutorial/WEB-INF/lib), and select GoogleSearch (the WSDL file).

Your file might be in a subdirectory of the lib directory. When you extracted it from the zip file, it was in a base directory called googleapi.

6. Click Finish to create the Web service model.

The GoogleSearchModel object is created in the main module.

 The figure on the left shows the GoogleSearchModel object created in the main module. The figure on the right shows the code.

7. Double-click the GoogleSearchModel node to view the code in the GoogleSearchModel class.

This Web service has a few operations that can be used. The following tasks focus only on the doGoogleSearch operation.



Note - When you look at your application file structure, you see a new folder named stubs. This folder was created by the Web Service Model wizard as a package to store any stub classes that are needed to support the use of Web services.

This is one of many great benefits provided the Web service model wizard. To use a Web service, there are many classes that need to be created. Browse this package folder to see how much work was actually performed.

Rest assured that you will not have to look at these files. All of the tedious work is done for you. You only need to work with the Web service model class and, even then, it requires only minimal manual coding, or most times, none at all.