I am confused about how SOAP messages and WSDL fit together? I have started looking into SOAP messages such as:
POST /InStock HTTP/1.1 Host: www.example.org Content-Type: application/soap+xml; charset=utf-8 Content-Length: nnn <?xml version="1.0"?> <soap:Envelope xmlns:soap="http://www.w3.org/2001/12/soap-envelope" soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding"> <soap:Body xmlns:m="http://www.example.org/stock"> <m:GetStockPrice> <m:StockName>IBM</m:StockName> </m:GetStockPrice> </soap:Body> </soap:Envelope>
Are all SOAP messages WSDL's? Is SOAP a protocol that accepts its own 'SOAP messages' or 'WSDL's? If they are different, then when should I use SOAP messages and when should I use WSDL's?
Some clarification around this would be awesome.
A WSDL is an XML document that describes a web service. It actually stands for Web Services Description Language. SOAP is an XML-based protocol that lets you exchange info over a particular protocol (can be HTTP or SMTP, for example) between applications.
1. WADL is an XML file-format, whereas WSDL is an XML language for describing web services. 2. WADL is a machine-readable description of HTTP based REST web services.
A SOAP message is an XML document that consists of a SOAP envelope, an optional SOAP header, and a SOAP body. The SOAP message header contains information that allows the message to be routed through one or more intermediate nodes before it reaches its final destination.
WSDL, or Web Service Description Language, is an XML based definition language. It's used for describing the functionality of a SOAP based web service. WSDL files are central to testing SOAP-based services.
A SOAP document is sent per request. Say we were a book store, and had a remote server we queried to learn the current price of a particular book. Say we needed to pass the Book's title, number of pages and ISBN number to the server.
Whenever we wanted to know the price, we'd send a unique SOAP message. It'd look something like this;
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetBookPrice xmlns:m="http://namespaces.my-example-book-info.com"> <ISBN>978-0451524935</ISBN> <Title>1984</Title> <NumPages>328</NumPages> </m:GetBookPrice> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
And we expect to get a SOAP response message back like;
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <SOAP-ENV:Body> <m:GetBookPriceResponse xmlns:m="http://namespaces.my-example-book-info.com"> <CurrentPrice>8.99</CurrentPrice> <Currency>USD</Currency> </m:GetBookPriceResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
The WSDL then describes how to handle/process this message when a server receives it. In our case, it describes what types the Title, NumPages & ISBN would be, whether we should expect a response from the GetBookPrice message and what that response should look like.
The types would look like this;
<wsdl:types> <!-- all type declarations are in a chunk of xsd --> <xsd:schema targetNamespace="http://namespaces.my-example-book-info.com" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <xsd:element name="GetBookPrice"> <xsd:complexType> <xsd:sequence> <xsd:element name="ISBN" type="string"/> <xsd:element name="Title" type="string"/> <xsd:element name="NumPages" type="integer"/> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="GetBookPriceResponse"> <xsd:complexType> <xsd:sequence> <xsd:element name="CurrentPrice" type="decimal" /> <xsd:element name="Currency" type="string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types>
But the WSDL also contains more information, about which functions link together to make operations, and what operations are avaliable in the service, and whereabouts on a network you can access the service/operations.
See also W3 Annotated WSDL Examples
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With