End-to-End Binary SOAP Attachment 2: Creating the Web Service
The goal of this lesson is to create a web application that contains a web service. You implement the web service as a stateless session bean.
You can download a complete sample of the web service from the NetBeans Samples Catalog.
Lessons In This Tutorial
Creating the Web Application
In this section, you create a Java EE web application. To this application, you add the images that the web service will pass as binary data.
To create the web application:
Choose File > New Project (Ctrl-Shift-N on Linux and Windows, ⌘-Shift-N on MacOS). The New Project wizard appears. Select Web Application from the Java Web category and click Next. The Name and Location page opens.
FlowerAlbumServicein the Project Name field. Select the location you want for this project. Keep the default settings for the other options and click Next. The Server and Settings page opens.
Select the GlassFish server and Java EE version Java EE 6 Web or Java EE 7 Web.
Click Finish. The
FlowerAlbumServiceproject is created and appears in the Projects window.
Right-click the Source Packages node and select New > Java Package.
Alternatively, select New > Other and select Java Package in the Java category of the New File wizard.
Name the package
org.flower.resources. Click Finish.
Copy the following images into
The project now has the package
org.flower.resources in the Source Package. No other contents have been added.
Adding the Web Service
In this section you create a web service in the web application. You create the service as a stateless session bean. You add the following web operations to the service:
An operation that takes the name of a flower and gets its associated
An operation that gets thumbnails of all the flower images and return them as a
To add the web service:
In the Projects window, right-click the
FlowerAlbumServiceproject node and choose New > Web Service. Alternatively, choose New > Other and then select Web Service under Web Services in the New File wizard. The New Web Service wizard opens.
In the New Web Service wizard, type
FlowerServicein Web Service Name and
org.flower.servicein Package Name. Select Create Web Service from Scratch. Select Implement Service as Stateless Session Bean. Click Finish.
The web service appears in the project’s nodes in the Projects window. The Source Packages directory includes the service package and the resources package.
FlowerService.javain the editor. Switch to the Design view. A form appears in which you can add operations and quality of service elements to the web service.
Click Add Operation. The Add Operation wizard opens.
Name the operation
getFlower. In the Return Type field, type or browse for
In the Parameters tab, click Add. Name the parameter
nameand accept the default
Open the Exceptions tab. Add an
Click OK and close the wizard. Then click Add Operation again, and add an operation with the following properties:
Return type: java.util.List
*Exception: * IOException
The Design view now shows the
getThumbnails operations. Switch to the List View of both operations and you see all their parameters.