此内容没有您所选择的语言版本。

Chapter 37. Implementing a WS Client


37.1. WS Client Overview

Overview

The key object in a WS client is the WS client proxy object, which enables you to access the remote Web service by invoking methods on the SEI. The proxy object itself can easily be instantiated using the jaxws:client element in Spring XML.

Demonstration location

The code presented in this chapter is taken from the following demonstration:
cxf-webinars-jboss-fuse-6.3/customer-ws-client
For details of how to download and install the demonstration code, see Chapter 34, Demonstration Code for Camel/CXF

WSDL contract

The WSDL contract is a platform-neutral and language-neutral description of the Web service interface. It contains all of the metadata that a client needs to find a Web service and invoke its operations. You can generate Java stub code from the WSDL contract, which provides an API that makes it easy to invoke the remote WSDL operations.

Service Endpoint Interface (SEI)

The most important piece of the generated stub code is the SEI, which is an ordinary Java interface that represents the Web service interface in the Java language.

WS client proxy

The WS client proxy is an object that converts Java method invocations to remote procedure calls, sending and receiving messages to a remote instance of the Web service across the network. The methods of the proxy are exposed through the SEI.
Note
The proxy type is generated dynamically by Apache CXF at run time. That is, there is no class in the stub code that corresponds to the implementation of the proxy (the only relevant entity is the SEI, which defines the proxy's interface).

The CustomerService client

To take a specific example, consider the customer-ws-client demonstration, which is available from the following location:
cxf-webinars-jboss-fuse-6.3/customer-ws-client
Figure 37.1, “Building a WS Client” shows an overview of the files required to implement and build the WS client.

Figure 37.1. Building a WS Client

Building a WS Client

Implementing and building the WS client

To implement and build the sample WS client shown in Figure 37.1, “Building a WS Client”, starting from scratch, you would perform the following steps:
  1. Obtain a copy of the WSDL contract.
  2. Generate the Java stub code from the WSDL contract using a WSDL-to-Java converter, ws2java. This gives you the SEI, CustomerService, and its related classes, such as Customer.
  3. Implement the main client class, ClientInvoker, which invokes the Web service operations. In this class define a bean property of type, CustomerService, so that the client class can receive a reference to the WS client proxy by property injection.
  4. In a Spring XML file, instantiate the WS client proxy and inject it into the main client class, ClientInvoker.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.