WSDL (WebService Description Language) file introduction

Source: Internet
Author: User
Tags webservice annotation wsdl

First, the WSDL  

1. Part of the WSDL document

<portType> :actions performed by Web service

<message> :messages used by Web service

<types> :data types used by Web service

<binding> :communication protocol used by Web service

2. Introduction to WSDL elements

In order to not create ambiguity, the WSDL specification defines special nouns to express functions and services.

The <portType> :<porttype> element is the most important WSDL element. It can describe a Web Service, operations that can be performed, and related messages. You can compare <portType> elements to a library of functions (or a module, or a class) in a traditional programming language.

<operation> :<operation> is an abstract description of the operations supported in the service, typically a single operation describes a request/response message pair for an access portal.

<message> : The <message> element defines a data element for an operation. Each message is made up of one or more parts. These parts can be compared to the parameters of a function call in a traditional programming language. Abstract typed definition of the data structure of the communication message. Use the type defined by types to define the data structure of the entire message.

<types>: The <types> element defines the type of data used by the webservice. For maximum platform neutrality, WSDL uses XML Schema syntax to define the data type.

<binding> : The <binding> element defines the message format and protocol details for each port.

3. Example of a simplified fragment of a WSDL document  
<messagename= "Gettermrequest">   < Partname= "term"type= "Xs:string"/></message><messagename= "Gettermresponse">   < Partname= "value"type= "Xs:string"/></message><PortTypename= "Glossaryterms">  <Operationname= "Getterm">        <inputmessage= "Gettermrequest"/>        <Outputmessage= "Gettermresponse"/>  </Operation></PortType>   

A In this example , the,<porttype> element defines "Glossaryterms" as the name of a port, and "Getterm" is defined as the name of an operation.

B , the operation "Getterm" has an input message named "Gettermrequest", and an output message named "Gettermresponse".

C ,The <message> element defines the part of each message, and the associated data type.

  Note: The specific WSDL syntax is detailed in the AppendixWebService Description Language wsdl . pdf

Https://files.cnblogs.com/files/jiyukai/WebService Description Language wsdl detailed. pdf

Second, use WebService annotations to modify the WSDL file

  1. WebService Annotations Overview

The contents of the WSDL file are generally generated by default, but in order to better provide the developer with a manual, some simple modifications are generally required. At least, we should not expose our package structure. The targetnamespace default is the inverted package name, which has exposed our package structure. By adding the following annotations to the class file, you can modify the WSDL-generated elements instead of directly modifying the WSDL file, and it is not valid to directly modify the WSDL file.

WebService the annotations include:

A, @WebService-Define service-annotation Location: class name

B, @WebMethod-Definition Method-Annotation Location: method

C, @WebResult-Define return value – Note location: return value

D, @WebParam-Define parameters – Note location: Method parameters

2. WebService explanation of annotation types

(1 ) WebService Annotations

@WebService label a class or interface to be exposed as a Web services, which is used to decorate a class or interface that contains properties such as:

targetnamespace Properties: define namespace, default to "http:/" + "Package name inverted"

name Properties: The name of the Web service, which defaults to the class name of the publishing service.

  serviceName: The WS service noun, which by default adds a service after the class name

Endpointinterface Properties: defines the full name of the service endpoint interface for the service abstraction Web service contract, and the interface must also declare the WebService annotation, including that the annotation of the method must also be added to the interface, otherwise it will be invalid. And WS is in the absence of annotations. When generating WS, an annotation is generated automatically. So you don't have to specify an interface.

   

(2 ) WebMethod Annotations

@WebMethod This annotation is used on methods to modify methods that are exposed externally, including the following properties:

OperationName property: The name of the wsdl:operation that matches this method

Exclude Properties: Labels If this method is exposed, default to False

    

  Note: If @webmethod is not specified on all public methods, the default is that all public methods are externally exposed.

  ( 3 ) Webresult Annotations

@WebResult defines the return value, the return value type cannot be an interface class or an abstract class, and must have a constructor with no parameters, containing the property

name property: The name of the return value

  

  ( 4 ) Webparam Annotations

@WebParam used to modify parameter names, such as example

name Property: name of the parameter

Third, WebService note Considerations for annotations

(1) Through WebService annotations, you can describe the Web service more like. This generates a WSDL document.

(2) When WebService annotations are modified, the client-generated code is also affected.

(3) The method name and parameter name of the call also changed.

(4) Even if the source code is not modified, only the annotations are modified, the client's code must also be regenerated (note that it is generated rather than downloaded). Otherwise the call will fail.

(5) Cost-effectively invoke code, still using the Wsimport tool

(6) After adding the @webservice annotation to the class, all non-static methods in the class will be published externally

(7) If you want a method to be public, you can add @webmethod (exclude=true) on the method to prevent public disclosure.

(8) If a @webservice annotation is added on a class, there must be at least one method that can be exposed by this class, or it will fail to start.

(9) Protected, private, final, static method cannot be disclosed to the public

WSDL (WebService Description Language) file introduction

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.