Using SoapUI for testing your webservice

In my previous post I showed you how you can use Ant and XFire to create a client for your webservice. Another, even nicer and easier way, to test your webservice is to make use of soapUI. This is a free tool (I haven’t used the Pro version yet) with which you can easily create a SOAP request and send them to your webservice and see the repsonse that is send back by the webservice. Beside just sending SOAP requests you can also have executed Groovy scripts with which you can prepare the state of your database for instance, so you can create a full and clean test cycle.
I have installed the standalone version of soapUI version 1.7 which can be downloaded here. After installing it, you can start it and create a new WSDL project:

The WSDL I am pointing to, is the WSDL of the service I deployed in this post. Here is the content of the WSDL:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://model.pascalalma.net" xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope" xmlns:soapenc11="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenc12="http://www.w3.org/2003/05/soap-encoding" xmlns:tns="http://net.pascalalma.services/BookService" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://net.pascalalma.services/BookService">
  <wsdl:types>
    <xsd:schema targetNamespace="http://model.pascalalma.net" elementFormDefault="qualified" attributeFormDefault="qualified">
      <xsd:complexType name="ArrayOfBookObject">
        <xsd:sequence>
          <xsd:element name="BookObject" type="ns1:BookObject" nillable="true" minOccurs="0" maxOccurs="unbounded" />
        </xsd:sequence>
      </xsd:complexType>
      <xsd:complexType name="BookObject">
        <xsd:sequence>
          <xsd:element name="author" type="xsd:string" minOccurs="0" nillable="true" />
          <xsd:element name="isbn" type="xsd:string" minOccurs="0" nillable="true" />
          <xsd:element name="title" type="xsd:string" minOccurs="0" nillable="true" />
        </xsd:sequence>
      </xsd:complexType>
    </xsd:schema>
    <xsd:schema targetNamespace="http://net.pascalalma.services/BookService" elementFormDefault="qualified" attributeFormDefault="qualified">
      <xsd:element name="myAnswer" type="ns1:ArrayOfBookObject" />
    </xsd:schema>
  </wsdl:types>
  <wsdl:message name="getBooksRequest" />
  <wsdl:message name="getBooksResponse">
    <wsdl:part element="tns:myAnswer" name="myAnswer" />
  </wsdl:message>
  <wsdl:portType name="BookServiceImpl">
    <wsdl:operation name="getBooks">
      <wsdl:input message="tns:getBooksRequest" name="getBooksRequest" />
      <wsdl:output message="tns:getBooksResponse" name="getBooksResponse" />
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="BookServiceHttpBinding" type="tns:BookServiceImpl">
    <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
    <wsdl:operation name="getBooks">
      <wsdlsoap:operation soapAction="urn:getBooks" />
      <wsdl:input name="getBooksRequest">
        <wsdlsoap:body use="literal" />
      </wsdl:input>
      <wsdl:output name="getBooksResponse">
        <wsdlsoap:body use="literal" />
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="BookService">
    <wsdl:port binding="tns:BookServiceHttpBinding" name="BookServiceHttpPort">
      <wsdlsoap:address location="http://localhost:8080/XFireTest/services/BookService" />
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

As you can see it is a simple WSDL:
there are no input parameters for the service and it will return a list (array) of bookObjectTypes. After creation of the soapUI project, you directly create tests for your webservice since the checkbox asking to create a SOAP request for each operation was checked. If you double click the request you can see the content of the SOAP request in the main window:

Since my webservice doesn’t have any input parameters, it is very simple request. When we click the green arrow the request is sent and we will see the SOAP response we got back from the server:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soap:Body>
      <myAnswer xmlns="http://net.pascalalma.services/BookService">
         <ns1:BookObject xmlns:ns1="http://model.pascalalma.net">
            <author xmlns="http://model.pascalalma.net">Pascal Alma</author>
            <isbn xmlns="http://model.pascalalma.net">1313131313</isbn>
            <title xmlns="http://model.pascalalma.net">XFire Tutorial</title>
         </ns1:BookObject>
         <ns1:BookObject xmlns:ns1="http://model.pascalalma.net">
            <author xmlns="http://model.pascalalma.net">Pascal Alma</author>
            <isbn xmlns="http://model.pascalalma.net">1413135316</isbn>
            <title xmlns="http://model.pascalalma.net">XFire Advanced</title>
         </ns1:BookObject>
      </myAnswer>
   </soap:Body>
</soap:Envelope>

So now we know the webservice is working. To make it a good test case, we need to create a new testsuite in our project and add testcases to it. With these test cases you can send your custom SOAP requests and check the response with asserts. You can do this by right-clicking the BookServiceHttpBinding and choose ‘Generate Testsuite’. You will now get a testsuite with one test case (in my situation). If you expand the Test Steps node and double click at the TestRequestStep getBooks you will see the simple SOAP request again in the main window. But this time you can right-click in the bottom of the window to add assertions:

This way it is not only checking whether the service is reached, but it also checks if the content of the reponse is what you would expect to be returned by the service. This is just a small example of all the things you can do with soapUI but I hope when you play around with it, you will get enthousiastic about the tool as I am.

About Pascal Alma

Pascal is a senior IT consultant and has been working in IT since 1997. He is monitoring the latest development in new technologies (Mobile, Cloud, Big Data) closely and particularly interested in Java open source tool stacks, cloud related technologies like AWS and mobile development like building iOS apps with Swift. Specialties: Java/JEE/Spring Amazon AWS API/REST Big Data Continuous Delivery Swift/iOS
This entry was posted in SoapUI, Web Service and tagged , . Bookmark the permalink.

154 Responses to Using SoapUI for testing your webservice

  1. jayachandra says:

    Hi , I am New to SOAP UI Tool can u explain the functioning of tool and utilisation of tool

  2. Henk Bekkering says:

    I have the same problem. I use SoapUI 3.5, and sometimes I get the soapUI javax.net.ssl.SSLException received fatal alert unexpected_message error.

    I have noticed that the certificate is not (completely) correct, the name of the machine is not the name as in the certificate.

    But I have no solution yet 😦

  3. Sabir says:

    Hi Pascal,
    I’m currently using the SOAP UI 3.5 to attach client certificate.
    On the preference tab I did mention the certificate key location.
    Also i did attach the certificate to the web service and gave the password.
    Still i dont see the certificate getting attached to the message header.
    The Web Service throws forbidden error from the server.
    Any suggestion would help
    Regards
    Sabir

  4. Pascal Alma says:

    @Sabir,
    I guess you followed these steps: http://www.soapui.org/userguide/projects/wss.html
    otherwise you should check if you forgot a step, because this functionality has worked for me (in older versions).

    @Henk
    I do not have a simple solution for this as I said before. This could have many reasons and I do not known if soapUI is doing something wrong here.
    I guess you are not able to recreate the certificate so that it matches the name of the machine? That would remove one possibility as a reason. And can you supply some more error info, maybe it triggers someone else who has been in the same situation.

Comments are closed.