blob: 4b406f56443a51c05ce46ec26cf70bf1382371c3 [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= 通过 Web 服务传递二进制数据,第 1 部分:概述
:jbake-type: tutorial
:jbake-tags: tutorials
:jbake-status: published
:icons: font
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:description: 通过 Web 服务传递二进制数据,第 1 部分:概述 - Apache NetBeans
:keywords: Apache NetBeans, Tutorials, 通过 Web 服务传递二进制数据,第 1 部分:概述
在本教程中,将创建一个包含 Web 服务的 Java EE Web 应用程序,该应用程序将作为无状态会话 Bean 来实现。同时还会向该 Web 应用程序添加包含四个 JPEG 文件的包。Web 服务有两种操作可供客户端访问,一是获取单个图像,二是以缩略图形式获取一组所有 4 个图像。将添加一些私有方法,用于将 JPEG 文件转换为字节数组,然后将这些字节数组转换为 ``Image`` 对象。在 Java EE 中,将这些私有方法直接放在 Web 服务中,因为 Web 服务还是一个 EJB
在创建 Web 服务后,将其部署到 GlassFish Server 3.1 或更高版本的实例中。使用 NetBeans IDE 的内置 Web 服务测试器可查看样例 SOAP 请求和响应消息。
默认的 JAX-WS 服务基础结构无法通知客户端需要将二进制数据解释为 JPEG 文件。因此,将生成一个 XML 方案的副本以及 WSDL 文件,然后编辑 XML 方案以告知任何客户端期望的返回元素是 ``image/jpeg`` 内容类型。还将更改服务代码以使用定制的 WSDL 和方案。
最后,将创建一个 Java 客户端应用程序,用于在相册中显示通过 Swing 组件创建的图像。
*本教程中的课程*
image::images/netbeans-stamp-80-74-73.png[title="此页上的内容适用于 NetBeans IDE 7.2、7.3、7.4 和 8.0"]
1. => 概述
2. link:./flower_ws.html[+创建 Web 服务+]
3. link:./flower-code-ws.html[+对 Web 服务进行编码和测试+]
4. link:./flower_wsdl_schema.html[+修改方案文件和 WSDL 文件以传递二进制数据+]
5. link:./flower_swing.html[+创建 Swing 客户端+]
== 本教程所需要的软件
*要学习本教程,您需要具备以下软件和资源。*
|===
|软件或资源 |要求的版本
|link:https://netbeans.org/downloads/index.html[+NetBeans IDE+] |Java EE 下载包
|link:http://www.oracle.com/technetwork/java/javase/downloads/index.html[+Java 开发工具包 (JDK)+] |版本 7 或 8
|符合 Java EE 规范的 Web 服务器或应用服务器 |link:http://glassfish.java.net/[+GlassFish Server Open Source Edition 3.1 或更高版本+]
|本教程中使用的图片 |link:images/rose.jpg[+rose.jpg+]
link:images/sunflower.jpg[+sunflower.jpg+]
link:images/aster.jpg[+aster.jpg+]
link:images/honeysuckle.jpg[+honeysuckle.jpg+]
|===
*注:*GlassFish Server 可以随同 NetBeans IDE Java EE 下载包一起安装。或者,还可以访问 link:https://glassfish.java.net/download.html[+GlassFish Server 下载页+]。
*提示:*(可选)要解决疑难问题,可以link:https://netbeans.org/files/documents/4/2343/SoapWithAttachments.zip[+下载完整的样例+]并查看其源代码。
执行完本教程中的操作后,将具有一个可运行的 Java Swing 应用程序,它通过 Web 服务使用 JPEG 图像,具体结果显示如下。
image::images/running-client.png[title="显示从 Web 服务传递的所有鲜花图像的 JFrame"]
== 后续步骤:
link:./flower_ws.html[+创建 Web 服务+]
link:/about/contact_form.html?to=3&subject=Feedback:%20Flower%20Overview%20EE6[+发送有关此教程的反馈意见+]
== 另请参见
有关使用本教程前的背景信息,请参见以下资源:
* link:./jax-ws.html[+JAX-WS Web 服务入门指南+]
* link:../../docs/websvc/client.html[+开发 Web 服务客户端+]
* link:../javaee/javaee-gettingstarted.html[+Java EE 应用程序入门指南+]
* link:./wsit.html[+Advanced Web Service Interoperability+](高级 Web 服务互操作性)
要发送意见和建议、获得支持以及随时了解 NetBeans IDE Java EE 开发功能的最新开发情况,请link:../../../community/lists/top.html[+加入 nbj2ee@netbeans.org 邮件列表+]。