Summary of WSDL

Source: Internet
Author: User
Tags date1

 

WSDL: Web Services descirption language ).
 
A. The service provider sends all the rules used to call the Web service to the service requestor through the Web service description.
B. WSDL describes web services in a standard XML format.
C. It defines Web service operations and messages in an abstract way unrelated to the implementation language.
D. The operation and message are abstracted and then bound to the specific network protocol and endpoint.
E. The web service contains a set of abstract endpoints.
 
WSDL conceptual model:
1. What does a service do: the operations (methods) provided by the Service ). Corresponds to the porttype and operation elements.
2. How to access the service: data format details (types, message) and the necessary protocol for accessing service operations (binding ).
3. Where the service is located: The network address agreed by the specific protocol. Such as URL. (Service, port ).
 
Elements of WSDL
1. types is a data type defined container. The element defines the type of the XML element required in the message definition. The complextype element defines the specific types of XML elements and the order of the elements. If the complextype element is placed under the types element without being contained by the element, it defines a common data type. It can be referenced by multiple element elements.
 
For example:
<WSDL: types>
<XSD: Schema
Targetnamespace = "http://www.example.com/OnlineBanking/xsd"
Xmlns = "http://www.w3.org/2001/XMLSchema"
Xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl"
Elementformdefault = "qualified">
<XSD: complextype name = "transaction">
<XSD: sequence>
<XSD: Element minoccurs = "1" maxoccurs = "1"
Name = "Number" type = "XSD: int"/>
<XSD: Element minoccurs = "0" maxoccurs = "1"
Name = "checknumber" type = "XSD: int"/>
<XSD: Element minoccurs = "1" maxoccurs = "1"
Name = "date" type = "XSD: Date"/>
<XSD: Element minoccurs = "1" maxoccurs = "1"
Name = "Header" type = "XSD: string"/>
<XSD: Element minoccurs = "1" maxoccurs = "1"
Name = "amount" type = "XSD: float"/>
</XSD: sequence>
</XSD: complextype>

This is a complex type definition. It is a bit like defining a class called transaction, which has the attributes number, checknumber, date, header, and amount. A common data type structure is defined here.

<XSD: element name = "lookuptransactionsresponse">
<XSD: complextype>
<XSD: sequence>
<XSD: Element minoccurs = "0" maxoccurs = "unbounded"
Name = "Transactions" type = "xsd1: transaction"/>
</XSD: sequence>
</XSD: complextype>
</XSD: Element>
 
Here, an element is defined as lookuptransactionsresponse, which references the transaction set defined earlier. the data type elements defined here will be referenced in subsequent message definitions.
 
<XSD: element name = "lookuptransactions">
<XSD: complextype>
<XSD: sequence>
<XSD: Element minoccurs = "1" maxoccurs = "1"
Name = "accountnumber" type = "XSD: int"/>
<XSD: Element minoccurs = "0" maxoccurs = "1"
Name = "date1" type = "XSD: Date"/>
<XSD: Element minoccurs = "0" maxoccurs = "1"
Name = "date2" type = "XSD: Date"/>
<XSD: Element minoccurs = "1" maxoccurs = "1"
Name = "token" type = "XSD: base64binary"/>
</XSD: sequence>
</XSD: complextype>
</XSD: Element>
 
The data type defined here is a list of parameters, which are composed of accountnumber, date1, date2, and Token. Similar to the parameter list in someobject. lookuptransactions (accountnumber, date1, date2, token. Complextype is defined in the element, so the data type structure can only be lookuptransactions private.
</XSD: schema>
</WSDL: types>
 
2. Message defines the data structure of messages used in communication. What is it used in communication? Because WSDL is for the caller. Then I want to call your service. How should I write the SOAP request message? What is the format? The definition is provided here.

<WSDL: Message name = "lookuptransactionsresponse">
<WSDL: part name = "Parameters" element = "xsd1: lookuptransactionsresponse"/>
</WSDL: Message>
 
The data format returned by the message after the service is called is defined here. Its name is parameters, and the data type is xsd1: lookuptransactionsresponse.

<WSDL: Message name = "lookuptransactions">
<WSDL: part name = "Parameters" element = "xsd1: lookuptransactions"/>
</WSDL: Message>
 
This section defines the data to be transmitted when accessing the service.

3. porttype defines an interface that a service can access. Is an abstract set of operations supported by a port type. In fact, the service defines how many methods can be called.

There are two meanings: first, for a port (porttype), such as the SOAP port type and http port type. A port can contain any number of operations. Second, it defines the operation owned by the Service ).
 
<WSDL: porttype name = "onlinebankingporttype">
<WSDL: peration name = "lookuptransactions">
<WSDL: input message = "TNS: lookuptransactions"/>
<WSDL: utput message = "TNS: lookuptransactionsresponse"/>
</WSDL: peration>
</WSDL: porttype>
A method that can be accessed is defined here: lookuptransactions. The input parameter of this method is also called the inbound message. It is the TNS: lookuptransactions defined in the message. At the same time, this method also has a returned object, also called the play message, which is the TNS: lookuptransactionsresponse defined in the message.

<WSDL: porttype name = "chinastockwebservicesoap">
<WSDL: peration name = "getstockimagebycode">
<WSDL: Documentation
Xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/">
SDF
</WSDL: Documentation>
<WSDL: input message = "TNS: getstockimagebycodesoapin"/>
<WSDL: utput message = "TNS: getstockimagebycodesoapout"/>
</WSDL: peration>
</WSDL: porttype>

<WSDL: porttype name = "chinastockwebservicehttppost">
<WSDL: peration name = "getstockimagebycode">
<WSDL: Documentation xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/">
Test
</WSDL: Documentation>
<WSDL: input message = "TNS: getstockimagebycodehttppostin"/>
<WSDL: utput message = "TNS: getstockimagebycodehttppostout"/>
</WSDL: peration>
</WSDL: porttype>
 
This example defines two port types: soap and httppost.

Types, message, and porttype describe how to call WebService in an abstract way, regardless of the specific Web Service deployment. Note that the WSDL namespace is used here. No soap namespace is used. The namespace of the soap message will be used in subsequent binding and deployment.
 
4. Binding defines the binding of A porttype to a specific network transmission protocol or message transmission protocol.
 
<WSDL: Binding name = "onlinebankingportbinding"
Type = "TNS: onlinebankingporttype">
<Soap: Binding transport = "http://schemas.xmlsoap.org/soap/http"
Style = "document"/>
<WSDL: peration name = "lookuptransactions">
<Soap: peration soapaction = "http://www.example.com/OnlineBanking/LookupTransactions"
Style = "document"/>
<WSDL: input>
<Soap: Body use = "literal"/>
</WSDL: input>
<WSDL: utput>
<Soap: Body use = "literal"/>
</WSDL: utput>
</WSDL: peration>
</WSDL: Binding>
 
The port type onlinebankingporttype defined above is bound to the SOAP/HTTP protocol. The soap namespace is used for binding.
Soap: binding: indicates that the binding is in the SOAP protocol format. Transport specifies the transmission protocol. Style specifies the communication style. There are two styles: "RPC" and "document.
Soap: peration: Provides messages for soap service operations. Generally, you can specify the soapactionhttp header for this operation.
Soap: Body: Specifies how messages are displayed in the soap Body element.

5. deployment details of all access portals of a service. A service usually contains multiple access entries (such as URLs), each of which is described by a port.
6. Port describes the deployment details of a service access portal. Which web address (URL) is used for access and which port is bound.
<WSDL: Service name = "onlinebankingservice">
<WSDL: Port name = "onlinebankingport" binding = "TNS: onlinebankingportbinding">
<Soap: address location = "http: // localhost: 8080/axis2/services/onlinebankingservice"/>
</WSDL: Port>
</WSDL: Service>
 
Soap: address is the network address specified for soap service access.
 
The following example defines multiple access ports.

<WSDL: Service name = "chinastockwebservice">
<WSDL: Documentation xmlns: WSDL = "http://schemas.xmlsoap.org/wsdl/">
Test
</WSDL: Documentation>
<WSDL: Port name = "chinastockwebservicesoap"
Binding = "TNS: chinastockwebservicesoap">
<Soap: Address
Location = "http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx"/>
</WSDL: Port>
<WSDL: Port name = "chinastockwebservicesoap12"
Binding = "TNS: chinastockwebservicesoap12">
<Soap12: Address
Location = "http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx"/>
</WSDL: Port>
<WSDL: Port name = "chinastockwebservicehttpget"
Binding = "TNS: chinastockwebservicehttpget">
<Http: Address
Location = "http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx"/>
</WSDL: Port>
<WSDL: Port name = "chinastockwebservicehttppost"
Binding = "TNS: chinastockwebservicehttppost">
<Http: Address
Location = "http://www.webxml.com.cn/WebServices/ChinaStockWebService.asmx"/>
</WSDL: Port>
</WSDL: Service>

Client test code:
Public class onlinebankaxiomclient {

Private Static endpointreference targetepr =
New endpointreference (
"Http: // localhost: 8088/ums/services/onlinebankingservice ");

Public static omelement getloginpayload (string usernamestr, string passswordstr ){
Omfactory FAC = omabstractfactory. getomfactory ();

// The namespace must be a http://www.example.com/OnlineBanking/xsd,
// Not http://www.example.com/OnlineBanking.
// Because the namespace defines the Message format. The definition in the types element is
// <WSDL: types>
// <XSD: Schema
// Targetnamespace = "http://www.example.com/OnlineBanking/xsd"
//.......
// So the namespace defined by the data type is "http://www.example.com/OnlineBanking/xsd"
Omnamespace omns = FAC. createomnamespace (
Http://www.example.com/OnlineBanking/xsd, TNS ");
Omelement method = FAC. createomelement ("login", omns );
Omelement username = FAC. createomelement ("username", omns );
Username. addchild (FAC. createomtext (username, usernamestr ));
Method. addchild (username );

Omelement Password = FAC. createomelement ("password", omns );
Password. addchild (FAC. createomtext (password, passswordstr ));
Method. addchild (password );

Return method;
}

Public static void main (string [] ARGs ){
Try {
Omelement payload = getloginpayload ("dragon", "123 ");
Options = new options ();
Options. setto (targetepr );

// Soapaction = http://www.example.com/onlinebanking/login;
// Otherwise, "org. Apache. axis2.axisfault:
// The endpoint reference (EPR) for the Operation not found is
// Http: // localhost: 8088/ums/services/onlinebankingservice and the WSA action = urn: anonoutinop"
// Error.
// And must be consistent with the definition in the WSDL
// <WSDL: peration name = "login">
// <Soap: peration soapaction = "http://www.example.com/OnlineBanking/Login"
/// Style = "document"/>
 
Options. setaction ("http://www.example.com/OnlineBanking/Login ");
Options. setexceptiontobethrownonsoapfault (true );
Options. settransportinprotocol (constants. transport_http );

Serviceclient sender = new serviceclient ();
Sender. setoptions (options );
 
Omelement result = sender. sendreceive (payload );

String response = result. getfirstelement (). gettext ();
System. Out. println ("If login is valid:" + response );

} Catch (exception e ){
E. printstacktrace ();
}
}
}
Summary:
1. To use axiom to write client programs well, you must be fully familiar with the definition of the WSDL specification.
2. Pay attention to the namespace.
3. Although it is easy to develop the implementation (code --> WSDL) method from the bottom up, many knowledge points are unclear.
The top-down implementation (WSDL --> code) method is more controllable and can better grasp knowledge points.

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.