End-to-End Binary SOAP Attachment 2: Creating the Web Service

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例子。)

 

Creating the Web Application(創建web應用程序)

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.

 

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 Image.
  • An operation that gets thumbnails(縮略圖) of all the flower images and return them as a List.

 

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:

  • Name: getThumbnails
  • Return type: java.util.List
  • Exception: IOException

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

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章