End-to-End Binary SOAP Attachment 2: Creating the Web Service(端到端的通过SOAP传输二进制P附件2:创建Web Service)
The goal of this lesson is to create a web application that contains a web service.(这课的目的是要创建一个有web service的web应用程序。) You implement the web service as a stateless session bean.(web service是作为无状态session bean实现的。)
You can download a complete sample of the web service from the NetBeans Samples Catalog.(你可以在NetBeans Samples Catalog下载完整的web service例子。)
In this section, you create an EE6 web application. To this application, you add the images that the web service will pass as binary data.(在这一部分,你要创建一个EE6 web应用程序。在这个应用程序中你要添加图片,web service通过二进制的形式传递图片。)
To create the web application:(创建web应用程序:)
1.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.(选择File(文件)->New Project(新工程)(在Linux和Windows中快捷键是Ctrl-Shift-N ,在MacOs中快捷将是⌘-Shift-N))。新工程向导将会出现。在Java Web目录下选择Web Application,点击下一步。命名和位置页面将会出现。
2.Type FlowerAlbumService in 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.(在工程名字输入框输入FlowerAlbumService 。其他选项保持默认设置,点击下一步。服务器和设置页面将会打开。)
3.Select the GlassFish server 3.1 and Java EE version EE6 Web.(选择GlassFish服务器3.1版本和Java EE6)
Important: The GlassFish Server Open Source Edition must be Version 3.1 b27 or later. The customized schema file you create in Modifying the Schema and WSDL Files does not work in GlassFish server 3.0.1. Check the version of your the GlassFish server server in the Services window.
4.Click Finish. The FlowerAlbumService project is created and appears in the Projects window.
5.Right-click the Source Packages node and select New > Java Package. The New Java Package wizard opens.
6.Name the package org.flower.resources. Click Finish.
7.Copy the following images into org.flower.resources:
The project now has the package org.flower.resources in the Source Package. No other contents have been added.
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:
To add the web service:
1.In the Projects window, right-click the FlowerAlbumService project 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.
2.In the New Web Service wizard, type FlowerService in Web Service Name and org.flower.service in 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.
3.Open FlowerService.java in 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.
4.Click Add Operation. The Add Operation wizard opens.
5.Name the operation getFlower. In the Return Type field, type or browse for java.awt.Image.
6.In the Parameters tab, click Add. Name the parameter name and accept the default java.lang.String type.
7.Open the Exceptions tab. Add an IOException.
8.Click OK and close the wizard. Then click Add Operation again, and add an operation with the following properties:
The Design view now shows the getFlower and getThumbnails operations. Switch to the List View of both operations and you see all their parameters.
11111
11111111
3333333333
444444444
55555555555