WSDL file example: A sample SOAP web service contract

If you’re learning how to consume or provide SOAP services, you might find this free WSDL file example useful.

A Web Services Description Language (WSDL) document is a standard way of describing a web service. A WSDL file is written in XML, and it defines the location of the web service, its operations (methods), the messages used by each operation, and the XML elements, or data types, within.

A WSDL file typically consists of the following sections:

  • The types element – which defines the data types (XML elements) that are used by the web service.
  • The message elements – each of which defines a message exchanged with the web service.
  • portType elements – which combine multiple messages into a single operation – for synchronous operations, this is usually one input and one output.
  • The binding element – which defines exactly how each operation will take place over the network (SOAP, in this example).
  • The service element – which says where the service can be accessed from – in other words, its endpoint.

The example WSDL file: BookService.wsdl

The example WSDL file below was created in [Eclipse][1]. It describes a web service called BookService which exposes three synchronous (input/output) operations, using SOAP binding:

  • GetBook – to get information about a single book from the collection
  • AddBook – to add a book to the collection
  • GetAllBooks – to retrieve all books from the collection

Note that although this example WSDL describes a SOAP service, WSDL can also be used to describe other types of (non-SOAP) web services.

Feel free to use this WSDL in your own learning. If you end up doing something cool with it, let me know in the comments below!

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
	xmlns:tns="http://www.integrationwire.com/BookService/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="BookService"
	targetNamespace="http://www.integrationwire.com/BookService/">
	<wsdl:documentation>Definition for a web service called BookService,
		which can be used to add or retrieve books from a collection.
	</wsdl:documentation>
	
	<!-- 
		The `types` element defines the data types (XML elements)
		that are used by the web service.
	 -->
	<wsdl:types>
		<xsd:schema targetNamespace="http://www.integrationwire.com/BookService/">
			<xsd:element name="GetBook">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="ID" type="xsd:string" />
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="GetBookResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="ID" type="xsd:string"></xsd:element>
						<xsd:element name="Title" type="xsd:string"></xsd:element>
						<xsd:element name="Author" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="AddBook">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="Title" type="xsd:string"></xsd:element>
						<xsd:element name="Author" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="AddBookResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="ID" type="xsd:string"></xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
			<xsd:element name="GetAllBooks">
				<xsd:complexType />
			</xsd:element>
			<xsd:element name="GetAllBooksResponse">
				<xsd:complexType>
					<xsd:sequence>
						<xsd:element name="Book" minOccurs="0" maxOccurs="unbounded">
							<xsd:complexType>
								<xsd:sequence>
									<xsd:element name="ID" type="xsd:string"></xsd:element>
									<xsd:element name="Title" type="xsd:string"></xsd:element>
									<xsd:element name="Author" type="xsd:string"></xsd:element>
								</xsd:sequence>
							</xsd:complexType>
						</xsd:element>
					</xsd:sequence>
				</xsd:complexType>
			</xsd:element>
		</xsd:schema>
	</wsdl:types>
	
	
	<!-- 
		A wsdl `message` element is used to define a message
		exchanged between a web service, consisting of zero
		or more `part`s.
	 -->
	
	<wsdl:message name="GetBookRequest">
		<wsdl:part element="tns:GetBook" name="parameters" />
	</wsdl:message>
	<wsdl:message name="GetBookResponse">
		<wsdl:part element="tns:GetBookResponse" name="parameters" />
	</wsdl:message>
	<wsdl:message name="AddBookRequest">
		<wsdl:part name="parameters" element="tns:AddBook"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="AddBookResponse">
		<wsdl:part name="parameters" element="tns:AddBookResponse"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="GetAllBooksRequest">
		<wsdl:part name="parameters" element="tns:GetAllBooks"></wsdl:part>
	</wsdl:message>
	<wsdl:message name="GetAllBooksResponse">
		<wsdl:part name="parameters" element="tns:GetAllBooksResponse"></wsdl:part>
	</wsdl:message>
	
	<!-- 
		A WSDL `portType` is used to combine multiple `message`s 
		(e.g. input, output) into a single operation.
		
		Here we define three synchronous (input/output) operations
		and the `message`s that must be used for each.
	 -->
	<wsdl:portType name="BookService">
		<wsdl:operation name="GetBook">
			<wsdl:input message="tns:GetBookRequest" />
			<wsdl:output message="tns:GetBookResponse" />
		</wsdl:operation>
		<wsdl:operation name="AddBook">
			<wsdl:input message="tns:AddBookRequest"></wsdl:input>
			<wsdl:output message="tns:AddBookResponse"></wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="GetAllBooks">
			<wsdl:input message="tns:GetAllBooksRequest"></wsdl:input>
			<wsdl:output message="tns:GetAllBooksResponse"></wsdl:output>
		</wsdl:operation>
	</wsdl:portType>
	
	<!-- 
		The `binding` element defines exactly how each
		`operation` will take place over the network.
		In this case, we are using SOAP.
	 -->
	<wsdl:binding name="BookServiceSOAP" type="tns:BookService">
		<soap:binding style="document"
			transport="http://schemas.xmlsoap.org/soap/http" />
		<wsdl:operation name="GetBook">
			<soap:operation soapAction="http://www.integrationwire.com/BookService/GetBook" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="AddBook">
			<soap:operation soapAction="http://www.integrationwire.com/BookService/AddBook" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
		<wsdl:operation name="GetAllBooks">
			<soap:operation
				soapAction="http://www.integrationwire.com/BookService/GetAllBooks" />
			<wsdl:input>
				<soap:body use="literal" />
			</wsdl:input>
			<wsdl:output>
				<soap:body use="literal" />
			</wsdl:output>
		</wsdl:operation>
	</wsdl:binding>
	
	<!-- 
		The `service` element finally says where the service
		can be accessed from - in other words, its endpoint.
	 -->
	<wsdl:service name="BookService">
		<wsdl:port binding="tns:BookServiceSOAP" name="BookServiceSOAP">
			<soap:address location="http://www.example.org/BookService" />
		</wsdl:port>
	</wsdl:service>
</wsdl:definitions>

Don't want to miss the next post? Join my email list

Hello! Thanks for reading. I regularly post new articles here about integration, middleware, Java and containers. I share new content with my email subscribers first.

If you want to join my email list, all you have to do is fill in your email address and first name in the box below. I don't send spam, and you can unsubscribe at any time.

Leave a Comment