Difference between a SOAP message and a WSDL? Difference between a SOAP message and a WSDL? java java

Difference between a SOAP message and a WSDL?


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


A SOAP message is a XML document which is used to transmit your data. WSDL is an XML document which describes how to connect and make requests to your web service.

Basically SOAP messages are the data you transmit, WSDL tells you what you can do and how to make the calls.

A quick search in Google will yield many sources for additional reading (previous book link now dead, to combat this will put any new recommendations in comments)

Just noting your specific questions:

Are all SOAP messages WSDL's? No, they are not the same thing at all.

Is SOAP a protocol that accepts its own 'SOAP messages' or 'WSDL's? No - reading required as this is far off.

If they are different, then when should I use SOAP messages and when should I use WSDL's? Soap is structure you apply to your message/data for transfer. WSDLs are used only to determine how to make calls to the service in the first place. Often this is a one time thing when you first add code to make a call to a particular webservice.


We need to define what is a web service before telling what are the difference between the SOAP and WSDL where the two (SOAP and WSDL) are components of a web service

Most applications are developed to interact with users, the user enters or searches for data through an interface and the application then responds to the user's input.

A Web service does more or less the same thing except that a Web service application communicates only from machine to machine or application to application. There is often no direct user interaction.

A Web service basically is a collection of open protocols that is used to exchange data between applications. The use of open protocols enables Web services to be platform independent. Software that are written in different programming languages and that run on different platforms can use Web services to exchange data over computer networks such as the Internet. In other words, Windows applications can talk to PHP, Java and Perl applications and many others, which in normal circumstances would not be possible.

How Do Web Services Work?

Because different applications are written in different programming languages, they often cannot communicate with each other. A Web service enables this communication by using a combination of open protocols and standards, chiefly XML, SOAP and WSDL. A Web service uses XML to tag data, SOAP to transfer a message and finally WSDL to describe the availability of services. Let's take a look at these three main components of a Web service application.

Simple Object Access Protocol (SOAP)

The Simple Object Access Protocol or SOAP is a protocol for sending and receiving messages between applications without confronting interoperability issues (interoperability meaning the platform that a Web service is running on becomes irrelevant). Another protocol that has a similar function is HTTP. It is used to access Web pages or to surf the Net. HTTP ensures that you do not have to worry about what kind of Web server -- whether Apache or IIS or any other -- serves you the pages you are viewing or whether the pages you view were created in ASP.NET or HTML.

Because SOAP is used both for requesting and responding, its contents vary slightly depending on its purpose.

Below is an example of a SOAP request and response message

SOAP Request:

POST /InStock HTTP/1.1 Host: www.bookshop.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.bookshop.org/prices">     <m:GetBookPrice>     <m:BookName>The Fleamarket</m:BookName>     </m:GetBookPrice> </soap:Body> </soap:Envelope>

SOAP Response:

POST /InStock HTTP/1.1 Host: www.bookshop.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.bookshop.org/prices">     <m:GetBookPriceResponse>     <m: Price>10.95</m: Price>     </m:GetBookPriceResponse> </soap:Body> </soap:Envelope> 

Although both messages look the same, they carry out different methods. For instance looking at the above examples you can see that the requesting message uses the GetBookPrice method to get the book price. The response is carried out by the GetBookPriceResponse method, which is going to be the message that you as the "requestor" will see. You can also see that the messages are composed using XML.

Web Services Description Language or WSDL

WSDL is a document that describes a Web service and also tells you how to access and use its methods.

WSDL takes care of how do you know what methods are available in a Web service that you stumble across on the Internet.

Take a look at a sample WSDL file:

<?xml version="1.0" encoding="UTF-8"?> <definitions  name ="DayOfWeek"    targetNamespace="http://www.roguewave.com/soapworx/examples/DayOfWeek.wsdl"   xmlns:tns="http://www.roguewave.com/soapworx/examples/DayOfWeek.wsdl"   xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"    xmlns:xsd="http://www.w3.org/2001/XMLSchema"   xmlns="http://schemas.xmlsoap.org/wsdl/">    <message name="DayOfWeekInput">     <part name="date" type="xsd:date"/>   </message>   <message name="DayOfWeekResponse">     <part name="dayOfWeek" type="xsd:string"/>   </message>   <portType name="DayOfWeekPortType">     <operation name="GetDayOfWeek">       <input message="tns:DayOfWeekInput"/>       <output message="tns:DayOfWeekResponse"/>     </operation>   </portType>   <binding name="DayOfWeekBinding" type="tns:DayOfWeekPortType">     <soap:binding style="document"        transport="http://schemas.xmlsoap.org/soap/http"/>     <operation name="GetDayOfWeek">       <soap:operation soapAction="getdayofweek"/>       <input>         <soap:body use="encoded"            namespace="http://www.roguewave.com/soapworx/examples"            encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>       </input>       <output>         <soap:body use="encoded"            namespace="http://www.roguewave.com/soapworx/examples"               encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>       </output>     </operation>   </binding>   <service name="DayOfWeekService" >     <documentation>       Returns the day-of-week name for a given date     </documentation>     <port name="DayOfWeekPort" binding="tns:DayOfWeekBinding">       <soap:address location="http://localhost:8090/dayofweek/DayOfWeek"/>     </port>   </service> </definitions> 

The main things to remember about a WSDL file are that it provides you with:

  • A description of a Web service

  • The methods a Web service uses and the parameters that it takes

  • A way to locate Web services