'version='1.0' encoding='utf-8'? soap:Envelope xmlns:xsi='.
If you’re learning how to consume or provide SOAP services, you might find this free WSDL file example useful.
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 multiplemessage
s into a single operation – for synchronous operations, this is usually oneinput
and oneoutput
.- The
binding
element – which defines exactly how eachoperation
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!
organization.wsdl
<?xml version='1.0' encoding='UTF-8'?> |
<definitionsname='Organization' |
targetNamespace='urn:Organization' |
xmlns:tns='urn:Organization' |
xmlns:soap='http://schemas.xmlsoap.org/wsdl/soap/' |
xmlns:xsd='http://www.w3.org/2001/XMLSchema' |
xmlns:soapenc='http://schemas.xmlsoap.org/soap/encoding/' |
xmlns:wsdl='http://schemas.xmlsoap.org/wsdl/' |
xmlns='http://schemas.xmlsoap.org/wsdl/'> |
<messagename='FilterRequest'> |
<partname='params'type='xsd:string'/> |
</message> |
<messagename='FilterResponse'> |
<partname='result'type='xsd:string'/> |
</message> |
<messagename='LoginRequest'> |
<partname='login'type='xsd:string'/> |
<partname='password'type='xsd:string'/> |
</message> |
<messagename='LoginResponse'> |
<partname='result'type='xsd:string'/> |
</message> |
<portTypename='FilterPort'> |
<operationname='doFilter'> |
<inputmessage='tns:FilterRequest'/> |
<outputmessage='tns:FilterResponse'/> |
</operation> |
<operationname='login'> |
<inputmessage='tns:LoginRequest'/> |
<outputmessage='tns:LoginResponse'/> |
</operation> |
</portType> |
<bindingname='FilterBinding'type='tns:FilterPort'> |
<soap:bindingstyle='rpc'transport='http://schemas.xmlsoap.org/soap/http'/> |
<operationname='doFilter'> |
<soap:operationsoapAction='urn:FilterAction'/> |
<input> |
<soap:bodyuse='encoded'namespace='urn:Organization'encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> |
</input> |
<output> |
<soap:bodyuse='encoded'namespace='urn:Organization'encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> |
</output> |
</operation> |
<operationname='login'> |
<soap:operationsoapAction='urn:LoginAction'/> |
<input> |
<soap:bodyuse='encoded'namespace='urn:Organization'encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> |
</input> |
<output> |
<soap:bodyuse='encoded'namespace='urn:Organization'encodingStyle='http://schemas.xmlsoap.org/soap/encoding/'/> |
</output> |
</operation> |
</binding> |
<servicename='WSDLService'> |
<portname='FilterPort'binding='tns:FilterBinding'> |
<soap:addresslocation='http://localhost/api/wsdl/orgs/soap-server.php'/> |
</port> |
</service> |
</definitions> |
soap-client.php
<? |
$client=newSoapClient( 'http://localhost/wsdls/organization.wsdl', array( 'cache_wsdl'=>WSDL_CACHE_NONE ) ); |
try { |
$responseLogin=$client->login( 'test_user', 'test_password' ); // call login() from .wsdl |
if($responseLogin'success') { // if success |
$response=$client->doFilter( $params ); // call doFilter() from .wsdl |
?> |
<pre><?print_r( $response ); ?></pre> |
<? |
} |
} catch ( SoapFault$sf ) { |
echo$sf->getMessage(); |
// Full SoapFault message |
// echo '<pre>'; |
// var_dump( $sf ); |
// echo '</pre>'; |
// Analyze last request |
// $xml = $client->__getLastRequest(); |
// echo $xml; |
} |
?> |
soap-server.php
<? |
ini_set( 'soap.wsdl_cache_enabled', 0 ); |
ini_set( 'soap.wsdl_cache_ttl', 0 ); |
functionlogin( $login, $password ) |
{ |
return'some string'; |
} |
functiondoFilter( $params ) |
{ |
return'some string'; |
} |
$server=newSoapServer( 'organization.wsdl' ); |
$server->addFunction( 'login' ); |
$server->addFunction( 'doFilter' ); |
$server->handle(); |
?> |
commented May 30, 2018
Now i understood how SOAP works, its very good example |
commented Sep 28, 2018
Thank you very much so simple example. This is more than many words. |
commented Jan 4, 2019
Helped me to. Thanks. |
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment