Learn web services

Free, public SOAP web services example

Last update: June 12, 2022
Version 2.0.0

Introduction


TL;DR

If you want a simple, online web service, here is a WSDL for it:

Unknown

Firefox browser does not show us the WSDL document, just a blank page, so it is better to use the View Page Source menu to view the document. The WSDL document is available here in readable format.

Purpose of this site

Creating this site has two purposes. One is to provide some free, public, SOAP web services examples for learning, prototyping, teaching, testing, demonstrating tools, libraries or technologies. You may use these web services in blog posts, tutorials, videos. I would like to operate this website for reference in the long run.

The second purpose is to present client applications examples in different programming languages, using with different libraries. You can find the source code of the examples on GitHub what I am going to update regularly for the latest versions.

If you have a question, you can ask it in this Gitter room.

About SOAP web services

SOAP web services may be considered as best practices to exchange data between different applications, based on XML and mostly HTTP(S) protocol. Because of the formats and protocols are text based, they are readable by most of the applications and by humans as well. Web services became very popular, and easy to use on any platform and with any programming language.

SOAP web services are based on OASIS and W3C standards, and the WS-I organization provides some useful profiles to increase interoperability.

SOAP is a messaging protocol specifying an XML-based message format. This is called the SOAP envelope, encapsulating the message content. The WSDL format is based on XML as well, and specifies the interface - how to call the service, and what are the input and output formats.

Sometime the SOAP web services are considered legacy solutions today, because the RESTful web services are becoming increasingly popular. Also this is true, but the SOAP web services will be along for a long time.

Details


The web service accepts a name, and gives back a welcome message. (The service accepts only POST HTTP requests so you may not use it in a browser directly.)

The WSDL specifies the format of the request message. The content of the Name tag may be freely rewritten.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
   <soapenv:Header/>
   <soapenv:Body>
       <HelloRequest xmlns="http://learnwebservices.com/services/hello">
          <Name>John Doe</Name>
       </HelloRequest>
   </soapenv:Body>
</soapenv:Envelope>

This is the response provided by the web service. The Message tag contains the response message based on the request.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
       <HelloResponse xmlns="http://learnwebservices.com/services/hello">
          <Message>Hello John Doe!</Message>
       </HelloResponse>
   </soap:Body>
</soap:Envelope>

Error handling

In case a web service fails to process the SOAP message, it returns a SOAP fault.

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <soap:Fault>
         <faultcode>soap:Client</faultcode>
         <faultstring>Unmarshalling Error: Unexpected '&lt;' character in element (missing closing '>'?)
 at [row,col {unknown-source}]: [6,13]</faultstring>
      </soap:Fault>
   </soap:Body>
</soap:Envelope>

Other services


Celsius to Fahrenheit converter

Unknown

Server application


A Spring Boot server application serves the sample web services.

Source code

The application is available on Docker Hub.

If you would like to run with Docker, just use the following command.

docker run -p 8080:8080 --name my-lwsapp vicziani/lwsapp

Then check the http://localhost:8080 address!

Client implementations


To call the web service with SoapUI, create a new SOAP project in the application, and paste the URL of the WSDL document https://apps.learnwebservices.com/services/hello?WSDL into the Initial WSDL input field. SoapUI will process the WSDL file, and generate an example request. On the left side of the panel choose the SayHello operation, then the Request 1 example request. Give a name value in the Name tag (replacing the ? sign), then press the Submit request button.

Click on the picture to view the full animation that shows how to create a request with SoapUI!

SoapUI project file

Click on the picture to view the full animation that shows how to create a Postman project!

Postman Collection file

Apache JMeter may be used to test performance of SOAP web services.

Click on the picture to view the full animation that shows how to create a JMeter project.

JMeter project file

Use the following command to call the web service with curl.

curl --request POST --header "Content-Type: text/xml;charset=UTF-8"  \
  --data '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/> \
  <soapenv:Body> \
  <HelloRequest xmlns="http://learnwebservices.com/services/hello"><Name>John Doe</Name></HelloRequest> \
  </soapenv:Body></soapenv:Envelope>' \
  https://apps.learnwebservices.com/services/hello

Use the following command to call the web service with Wget.

wget -qO - --header "Content-Type: text/xml;charset=UTF-8"  \
  --post-data '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/> \
  <soapenv:Body> \
  <HelloRequest xmlns="http://learnwebservices.com/services/hello"><Name>John Doe</Name></HelloRequest> \
  </soapenv:Body></soapenv:Envelope>' \
  https://apps.learnwebservices.com/services/hello

Use the following command to call the web service with HTTPie.

echo '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Header/> \
  <soapenv:Body> \
  <HelloRequest xmlns="http://learnwebservices.com/services/hello"><Name>John Doe</Name></HelloRequest> \
  </soapenv:Body></soapenv:Envelope>' | \
  http -b POST https://apps.learnwebservices.com/services/hello  'Content-Type:text/xml;charset=UTF-8'

The following source code demonstrates calling the web service using JAX-WS RI library and jaxws-maven-plugin Maven plugin.

The source code is the same when using CXF with cxf-codegen-plugin Maven plugin.

HelloEndpointService service = new HelloEndpointService();
HelloEndpoint port = service.getHelloEndpointPort();
HelloRequest request = new HelloRequest();
request.setName("John Doe");
HelloResponse response = port.sayHello(request);
System.out.println(response.getMessage());

Source code with JAX-WS RI

Source code with CXF

The following source code demonstrates calling the web service using Spring Web Services library and maven-jaxb2-plugin Maven plugin.

HelloRequest helloRequest = new HelloRequest();
helloRequest.setName("John Doe");

JAXBElement<HelloResponse> response = (JAXBElement<HelloResponse>)
        webServiceTemplate.marshalSendAndReceive(new ObjectFactory().createHelloRequest(helloRequest));

System.out.println(response.getValue().getMessage());

Source code

The following source code demonstrates calling the web service using Apache Axis2/Java library, Axis2 Databinding Framework and axis2-wsdl2code-maven-plugin Maven plugin.

HelloEndpointServiceStub stub =
        new HelloEndpointServiceStub();

HelloEndpointServiceStub.HelloRequest helloRequest =
        new HelloEndpointServiceStub.HelloRequest();
helloRequest.setName("John Doe");

HelloEndpointServiceStub.HelloRequestE sayHelloE =
        new HelloEndpointServiceStub.HelloRequestE();
sayHelloE.setHelloRequest(helloRequest);

HelloEndpointServiceStub.HelloResponseE sayHelloResponseE =
        stub.sayHello(sayHelloE);
System.out.println(sayHelloResponseE
        .getHelloResponse()
        .getMessage());

Source code

The following source code demonstrates calling the web service using groovy-wslite library.

@Grab('com.github.groovy-wslite:groovy-wslite:1.1.2')
import wslite.soap.*

def client = new SOAPClient('https://apps.learnwebservices.com/services/hello')
def response = client.send {
    body {
        HelloRequest('xmlns':'http://learnwebservices.com/services/hello') {
          Name("John Doe")
        }
    }
}

println(response.HelloResponse.Message)

Source code

The following source code uses the Zeep framework to call the web service.

wsdl = 'https://apps.learnwebservices.com/services/hello?wsdl'
client = zeep.Client(wsdl=wsdl)
request = 'John Doe'
print(client.service.SayHello(request))

Source code

It is possible to call a web service from JavaScript running in the browser when it is in the same domain, or the Cross-Origin Resource Sharing (CORS) is properly configured.

const url = "https://apps.learnwebservices.com/services/hello";
const request = `<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <HelloRequest xmlns="http://learnwebservices.com/services/hello">
            <Name>John Doe</Name>
        </HelloRequest>
    </soapenv:Body>
 </soapenv:Envelope>`;

 const fetchData = {
    method: 'POST',
    body: request
 };

 fetch(url, fetchData)
   .then(function(response) {
     return response.text();
   })
   .then(function(xml) {
       const xmlDoc = new DOMParser().parseFromString(xml, "text/xml");
       console.log(xmlDoc.getElementsByTagNameNS("http://learnwebservices.com/services/hello", "Message")[0].textContent);
   })
   .catch(function(error) {
     console.log("Error calling webservice: " + error);
   });

You can try this online by pressing the Call the web service! button below.

Source code

The following source code demonstrates how to call a web service with Node.js and SOAP package.

const soap = require("soap");
const url = "https://apps.learnwebservices.com/services/hello?wsdl";
const args = {Name: "John Doe"};
soap.createClient(url, function(err, client) {
    client.SayHello(args, function(err, result) {
        console.log(result.Message);
    });
});

Source code

The following source code demonstrates how to call a web service with .NET Core using C# language.

HelloEndpointClient proxy = new HelloEndpointClient();
var request = new helloRequest
{
    Name = "John Doe"
};
var response = await proxy.SayHelloAsync(request);
Console.WriteLine(response.Body.HelloResponse.Message);

Source code

The following source code demonstrates how to call a web service with Ruby and Savon.

require 'savon'

client = Savon.client(wsdl: 'https://apps.learnwebservices.com/services/hello?WSDL')
response = client.call(
  :say_hello,
  soap_action: '',
  message: { 'Name' => 'John Doe' }
)
puts response.body[:hello_response][:message]

Source code

The following source code demonstrates how to call a web service with PHP and SOAP extension.

<?php

$client = new SoapClient('https://apps.learnwebservices.com/services/hello?wsdl');
echo $client
	->SayHello(
		[
				'Name' => 'John Doe'
		]
	)
	->Message
;

Source code

Contributors