Getting started with WebServices

zhaozj2021-02-11  233

Getting started with WebServices

- Practice

Previous article We briefly said some theories about WebServices, in which we will write a simple example. We know that the WebSerices specification is just a framework, and there are several versions of the Java implementation (such as Apache, BEA, IBM, Sun have implemented version), where we are using Apache's AXIS, so our environment is: JB8 WebLogic6. 1 or higher, because AXIS has been integrated in JB8. Let's get started below.

beforehand

In JB8, we have established a project helloworld, which has established a name for HelloWorld's WAR in this project, a name for HelloWorld, and a Class called BeanhelloWorld. In this Web Services we will put the SayHelloWorld () method in the Beanhelloworld class and the SayHello () method to the method of Web Services.

The project is as shown in Figure 1:

Figure one

In trouble

Below we started to publish this WebServices:

1. Right-click the beanhelloworld.java => Export AS A Web Service menu.

Figure 2:

Figure II

2, configure WebServices,

As shown in Figure 3, the EAR, WebApp is EAR, WAR in our project, of course, you can also create these two things; Toolket can choose apache axis and apache soap 2, both are apache to WebServices, we choose Apache Axes.

Figure three

3. The following interface will appear after these two steps are completed in accordance with the wizard. This interface is primarily to export our service description file (WSDL), where Interface or Class is selected to publish That interface, Class, if we are publishing Interface, you need to assign him to implement classes, that is, the Implementation Class will not be gray; GENERATE Client Stub is required to generate a test code for the client. Figure four

Figure four

4. In this step, it is mainly to set some properties of the service description file (WSDL).

Figure 5:

Deploy Scope: There are three, respectively, request, application, session, request: indicating that this object exists inside the SOAP request / response cycle; Application: Indicates that only one object instance is created, this object will handle all the requests; session: indicates The container creates an object instance for each customer and saves this object in multiple request / response sessions. By the way, the session in AXIS is implemented with the session of the web server.

The Location URL is the requested address of WebServices;

Other properties can be used by default.

Figure 5

5, this step is mainly the way to publish, as shown in Figure 6:

In the Selection Mode if it is Allow Selected Methods: I will release all public methods in BeanHelloWorld.java; Allow Selected Mothods: The selected method will be released; and Desallow SELECTED METHODS: It is just contrary to Allow SELECTED MOTHODS.

Figure 6

We use two methods of Sayhello () and SayhelloWorld () to become Web Services.

6. In this step we mainly set the SOAP version, as shown in Figure 8:

Set Type VESION to SOAP1.1. Then follow the wizard to complete the release, re-package can be deployed to WebLogic!

Figure eight

7. This step can be used to test our WebServices in this step.

afterwards

Let's take a look at the generated WSDL document, and the customer has this document to call the WEB Services that is just released.

Above this sentence is the beginning of the WSDL document

Targetnamespace = "http://bean.helloworld.test.com"

XMLns = "http://schemas.xmlsoap.org/wsdl/"

XMLns: ApacheSoAP = "http://xml.apache.org/xml-soap"

XMLns: IMPL = "http://bean.helloworld.test.com-impl"

XMLns: intf = "http://bean.helloworld.test.com" xmlns: soapenc = "http://schemas.xmlsoap.org/soap/encoding/"

XMLns: wsdl = "http://schemas.xmlsoap.org/wsdl/"

XMLns: wsdlsoap = "http://schemas.xmlsoap.org/wsdl/soap/"

XMLns: xsd = "http://www.w3.org/2001/xmlschema">

The above description is the namespace of this document to be used.

The above sentence is to define the WSDL document to use the composite data type, which is in line with XML Schema (XSD) to define a set of standard data types, and we only use simple data types in our document, so it is an control value.

The above paragraph defines four Message, which is described in the theoretical article to be the abstract type definition of the data structure of communication messages. Some people say why it is four instead of three or five, because we have released two methods, and each method has a request / response message, this

Message just requests a message of SayHello (), including parameters that call SayHello (), the name of this parameter is Name, type String.

This one

Message is a message response message, including SayHello () Return Value This return value is SayelloreTurn, the type String. The other two is a request / response message for calling the SayHelloWorld () method.

The above paragraph defines a porttype. In the theoretical articles we know that PortType is: Abstract collection for an operation supported by an access point type, which can be supported by one or more service access points.

Two Operations are included in this porttype, we know that Operation is: Abstract description of the operations supported in the service, generally a single Operation describes a request / response message pair for accessing portions. Below this Operation:

Contains a SayHellEquorEquest message and a SayElloreSponse message that is defined earlier. The parameter sequence of the ParameterOrder = "Name" call method SayHello ().

Namespace = "http://bean.helloWorld.test.com" Use = "encoded" />

Namespace = "http://bean.helloWorld.test.com" Use = "encoded" />

Namespace = "http://bean.helloWorld.test.com" Use = "encoded" />

Namespace = "http://bean.helloworld.test.com" Use = "encode" />

Above this paragraph defines binding, we know the binding: Binding: the specific protocol and data format specification for specific port types. The Binding structure defines a porttype and a specific network transport protocol or message transfer protocol. From this level, the description is related to the deployment of the specific service. For example, you can bind PortType to SOAP / HTTP, or you can bind PortType to MIME / SMTP.

The above describes the way Style = "RPC" (remote procedure call), specific network transport protocol TRANSPORT = "http://schemas.xmlsoap.org/soap/http", that is, the SOAP / HTTP protocol. Other descriptions are specifically described each Operation.

Above this paragraph defines Service, we know Service: Describe the deployment details of all access portals provided by a specific deployed Web service, and a service often contains multiple services access portals, and each access portal will be used A port element is described.

describes the binding defined above.

describes the specific request address

Of course, the above sentence is the end tag of the entire document.

There is a chance to take a look at the SOAP request or a document.

转载请注明原文地址:https://www.9cbs.com/read-4696.html

New Post(0)