Learn web services


Free, public SOAP web services example

Last update: March 13, 2019, Version 1.1.3

Introduction


TL;DR

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

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.

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.

Examples


Other provided web services

Celsius to Fahrenheit converter

An example web service

You may find an operating web service at the http://www.learnwebservices.com/services/hello URL that 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 file that specifies the interface is available at http://www.learnwebservices.com/services/hello?WSDL URL. (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 appropriate WSDL document is available here in readable format.

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>
      <SayHello xmlns="http://learnwebservices.com/services/hello">
         <HelloRequest>
            <Name>John Doe</Name>
         </HelloRequest>
      </SayHello>
   </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>
      <SayHelloResponse xmlns="http://learnwebservices.com/services/hello">
         <HelloResponse>
            <Message>Hello John Doe!</Message>
         </HelloResponse>
      </SayHelloResponse>
   </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>

Calling web service with SoapUI

To call the web service with SoapUI, create a new SOAP project in the application, and paste the URL of the WSDL document http://www.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.

The SoapUI project is available on GitHub.

Calling web service with CURL

Tip: try this site with the curl www.learnwebservices.com command.

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><SayHello xmlns="http://learnwebservices.com/services/hello"> \
  <HelloRequest><Name>John Doe</Name></HelloRequest> \
  </SayHello></soapenv:Body></soapenv:Envelope>' \
  http://www.learnwebservices.com/services/hello

Java web service client with JAX-WS RI or CXF

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.

URL url = new URL("http://www.learnwebservices.com/services/hello?wsdl");
HelloEndpointService service = new HelloEndpointService(url);
HelloEndpoint port = service.getHelloEndpointPort();
HelloRequest request = new HelloRequest();
request.setName("John Doe");
HelloResponse response = port.sayHello(request);
System.out.println(response.getMessage());

The source code with JAX-WS is available on GitHub.

The source code with CXF is available on GitHub.

Java web service client with Spring Web Services

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");
SayHello sayHello = new SayHello();
sayHello.setHelloRequest(helloRequest);

JAXBElement<SayHelloResponse> response = (JAXBElement<SayHelloResponse>)
        webServiceTemplate.marshalSendAndReceive(new ObjectFactory().createSayHello(sayHello));

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

The source code is available on GitHub.

Java web service client with Apache Axis2/Java

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.SayHello sayHello = 
        new HelloEndpointServiceStub.SayHello();
sayHello.setHelloRequest(helloRequest);

HelloEndpointServiceStub.SayHelloE sayHelloE = 
        new HelloEndpointServiceStub.SayHelloE();
sayHelloE.setSayHello(sayHello);

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

The source code is available on GitHub.

Calling web services with JMeter

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.

The JMeter project is available on GitHub.

Python web service client with Zeep

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

wsdl = 'http://www.learnwebservices.com/services/hello?wsdl'
client = zeep.Client(wsdl=wsdl)
request = {'Name': 'John Doe'}
print(client.service.SayHello(request))

The source code is available on GitHub.

Vanilla JS web service client

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.

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

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

 fetch(url, fetchData)
   .then(function(response) {
     return response.text();
   })
   .then(function(xml) {
       var 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 submit button below.

The source code is available on GitHub.

Node.js web service client with SOAP

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

var soap = require('soap');
var url = 'http://www.learnwebservices.com/services/hello?wsdl';
var args = {HelloRequest: {Name: 'John Doe'}};
soap.createClient(url, function(err, client) {
    client.SayHello(args, function(err, result) {
        console.log(result.HelloResponse.Message);
    });
});

The source code is available on GitHub.

C# client with .NET Core

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);

The source code is available on GitHub.

Ruby client with Savon

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

require 'savon'

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

The source code is available on GitHub.

Contributors