Detailed description of WSDL (1)

Source: Internet
Author: User

The WSDL document uses the Web Service Description Language to define the service.

This document includes the logical (abstract) Section and the specific section.

The abstract part is used to define data types and messages independent of implementation. The specific part defines how an endpoint can implement a service that can interact with the outside world.

We recommend that you define the WSDL document and XML schema before writing code, but this requires familiarity with the WSDL.

Logic:

Includes types, message, and porttype elements. In the types element, XML schema is used to define the structure of the data that constitutes the message. A certain number of message elements are used to define the format of the message used by the Service. The porttype element includes one or more operation elements to define the messages sent by operation.

Details:

Includes binding and service elements. The binding element describes how the data units described by the Message Element map to a specific data format. Service elements include one or more port elements, which are used to define an endpoint.

In general, a wsdl document consists of the following elements:

  • Definitions -- the root element of the WSDL document. The attributes of this element indicate the name of the WSDL document, the target namespace of the document, and the shorthand definition of the namespace of the WSDL document application.
  • Types: the XML style definition of data units, forming the building block of the messages used by the Service.
  • Porttype --- a set of operation elements that describe the service logical interfaces.
  • Operation-A description of the operations contained in a service. When an operation is called, the operation is defined as message transmission between two endpoints.
  • Binding --- description of the actual data format of an endpoint. A binding element defines how to map an abstract message to a specific data format. This element specifies information such as Parameter order and return value.
  • Service --- a collection of related port elements. These elements are stored in the database and defined by the user's organization endpoint.
  • Port -- endpoint defined by binding and physical address. This element aggregates all abstract definitions.

To design a WSDL:

1. Define the data types used by the Service

2. Define the message used by the Service

3. Define service interfaces

4. Define the bindings between messages and interfaces and the specific presentation mode of online data

5. Define the transmission details of each service.

The following sections describe each step:

1. Define Logical Data Units

When defining a service, the first thing you must consider is how the data used as a parameter exposed to the outside will be presented. Unlike those programs that use fixed Data Structure encoding, the Service must define their data in the form of logical units, which includes two steps:

1.1 split the data into logical units which can be mapped to the Data Type and referenced by the physical implementation of the service.

If you define a service interface that has been implemented, you must convert the Data Type of the operation to an XML Element for assembling the message. If you start from the beginning, you must define the building blocks used in your message build. In this way, they are meaningful from the implementation perspective.

Note 1: Define the available type system for service data units: According to the WSDL specification, you can use any type system. However, the XML schema defined in the W3C specification is the preferred standard type system. Therefore, the XML architecture is in the internal Type System of Apache cxf.

NOTE 2: XML schema is used to define how an XML document is built and what elements a document consists. These elements can use XML Schema types, such as XSD: Int or user-defined types. User-defined types are also constructed using combinations of XML elements, or they are built with strictly existing types. By combining the type definition and Element Definition, you can create complex XML documents that can contain complex data. When defining the data units used by a service, you can define them as types, which indicate the structure of the Message Components. You can also define your message units as elements that constitute the message structure.

NOTE 3: Considerations for generating data units: You can simply generate Logical Data Units that map directly to the data types you use in the service. When working in this way, you must closely follow the building model for building RPC-type applications. This is not a necessary strategy for building a service-oriented architecture program. The WebService Organization provides a certain number of manuals to define data units. In addition, W3C provides the main manual to teach you how to use XML schema to display data types.

1.2 add data units to the document

Depending on how you choose to generate the WSDL document and generate new data definitions, a large amount of knowledge is required. The cxf GUI tool provides a certain amount of help to describe the data type. Other XML editors provide different levels of help. No matter which editor you choose, it is important to have some document-related knowledge.

To define the data used in the WSDL, follow these steps:

A. determine all data units used by the interface

B. Generate a types element in the document.

C. Create a schema element as a child element of the types element.

D. The complex type is a set of elements. The complextype element is used to define the data type.

E. For each array, the complextype element is also used to define its data type.

F. For each complex type, the simple type can be derived, and the data Bureau type can be defined using the simpletype element.

G. For each Enumeration type, use the simpletype element to define the data type.

H. For each element, define that they use the element.

1.3 XML Schema simple types:

If a message component is of a simple type, you do not need to define a type for it. Complex types used by interfaces are also defined by simple types.

NOTE 1: The input simple type: the XML simple type is the primary placement element in the element. Simple types are also used in the base attributes of the restriction element and extension element. For simple types, XSD is always used as the prefix. For example, to specify the type int, you enter XSD: int in the type attribute.

<Element name = "simpleint" type = "XSD: int"/>

Cxf supports the following simple XML Schema types: XSD: String, XSD: normalizedstring, XSD: int, XSD: base64binary, and so on.

1.4 define complex data types:

XML Schema provides a flexible and powerful mechanism to build a data structure. You can create a data structure by creating a sequence of elements and attributes. You can expand existing types to create more complex types.

In addition, to construct complex data structures, you can describe specific types, such as enumeration types. Data of the Data Type has a specific value range, or the value of the data type must follow a specific pattern by extending or limiting the original type.

1.5 define the data structure:

In XML schema, a data unit is a collection of data fields defined by the type element. Three pieces of information are required to indicate a complex type:

A. The name of a complex element needs to be specified.

B. The first child element of the complex type is used to describe the behavior of the domain of the structure when it is put online.

C. Fields in each structure are defined by the element.

The following leizi is a complex type with two child elements:

The structure is as follows:

struct personalInfo{  string name;  int age;};

Corresponding WSDL document:

<complexType name="personalInfo">  <sequence>    <element name="name" type="xsd:string" />    <element name="age" type="xsd:int" />  </sequence></complexType>

Note 1: Types of complex types:

XML schema can be used to describe how the fields are organized when an XML document is displayed and displayed online. The first child element determines which complex type is referenced. The following three methods are used to define complex types of Behavior:

  • Sequence: All complex type fields must be displayed, and they must have a definite order, which is the same as the sequence defined by the type.
  • ALL: All complex types of domains are required, but the order does not matter.
  • Choice: only one element can appear in the message.

NOTE 2: define the structure:

You define data domains, which are composed of a struct. Each complex type element should include at least one element. Each element corresponds to a field in the defined data structure.

To fully describe the fields in the data structure, element must have two attributes:

Name attribute: indicates the name of the data field and is unique.

Type attribute: specifies the type of data stored in the domain. It can be a simple type or a complex type.

In addition, there are two important attributes: minoccurs and maxoccurs, which are used to set the upper and lower limit of the number of occurrences of the domain in the structure. By default, each field value occurs once. With these attributes, you can change the number of occurrences of a domain in the struct. In the following example, previusjobs occurs at least once and at most 7 times.

<complexType name="personalInfo>  <all>    <element name="name" type="xsd:string"/>    <element name="age" type="xsd:int"/>    <element name="previousJobs" type="xsd:string:             minOccurs="3" maxOccurs="7"/>  </all></complexType>

NOTE 3: Define attributes: in the XML document, attributes are included in the element. For example, in the complextype element, name is an attribute, which is usually followed by elements such as <sequence> and <all>. For example:
 

<complexType name="personalInfo>  <all>    <element name="name" type="xsd:string"/>    <element name="previousJobs" type="xsd:string"             minOccurs="3" maxOccurs="7"/>  </all>  <attribute name="age" type="xsd:int" use="optional" /></complexType>

1.6 define an array
 

Cxf supports two methods to define arrays. The first method is to define a complex type and use a simple element. Its maximum occurrence attribute is a value greater than 1, the second method is to use a soap array. The soap array provides the added functions, such as ability, to simplify the definition of arrays that are mostly arrays and send separated arrays.

Composite array: Composite array is a special sequence composite type. You can simply define a composite type by using a simple element and specify the maximum occurrence maxoccurs attribute of the element. For example, to define an array with two floating-point numbers, you can use the composite type as follows:

<complexType name="personalInfo>  <element name="averages" type="xsd:float" maxOccurs="20"/></complexType>

You can also define a minimum occurrence attribute.
 

Soap array: the soap array is defined through the SOAP-ENC: array, which is based on the WSDL: arraytype element.

<complexType name="TypeName">  <complexContent>    <restriction base="SOAP-ENC:Array">      <attribute ref="SOAP-ENC:arrayType"                  wsdl:arrayType="ElementType<ArrayBounds>"/>    </restriction>  </complexContent></complexType>

In the preceding syntax, typename specifies the newly defined array name, And elementtype specifies the Data Type of elements in the array. Arraybounds specifies the number of dimensions and elements in the array. The unit array uses [] and the multi-dimensional array uses [] [].

<complexType name="SOAPStrings">  <complexContent>    <restriction base="SOAP-ENC:Array">      <attribute ref="SOAP-ENC:arrayType"                 wsdl:arrayType="xsd:string[]"/>    </restriction>  </complexContent></complexType>

1.7 define types through extension

Similar to the main encoding language, XML Schema allows you to create data types that integrate existing data types. This mechanism is called extension. For example, you can create a new type named alieninfo, which integrates the personalinfo structure and uses Zheng Jia's new element planet.

Extension has four types:

A. Define the type name through the name attribute

B. Use the complexcontent element to specify that the new type will have an extra element.

C. The inherited class, called the base type, is specified through the base attribute.

D. The new types and attributes are defined in the extension element. Example:

<complexType name="alienInfo">  <complexContent>    <extension base="personalInfo">      <sequence>        <element name="planet" type="xsd:string"/>      </sequence>    </extension>  </complexContent></complexType>

1.8 use restriction to define the type

Simple Example

<simpleType name="SSN">  <restriction base="xsd:string">    <pattern value="\d{3}-\d{2}-\d{4}"/>  </restriction></simpleType>

1.9 define enumeration types:

<simpleType name="widgetSize">  <restriction base="xsd:string">    <enumeration value="big"/>    <enumeration value="large"/>    <enumeration value="mungo"/>  </restriction></simpleType>

2. Definition element:

The element in XML schema is an instance of an element. Most of the most basic elements are simple elements. Element elements are defined by a certain number of complex types. It has three attributes:

  • Name: A required attribute to specify the element name.
  • Type: Specifies the element type, which can be the original type of any XML schema or any named compound type. This attribute can be omitted if the type has been defined.
  • Nillable: Specifies whether an element can be ignored from a document. If it is true, the element can be ignored in any data file generated based on the schema.

An element can have a built-in type definition. The built-in type is specified by composite type elements or simple type elements. Once you confirm whether the data type is compound or simple, you can define any data type you need. Built-in type definition is not recommended because it does not support reuse.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.