Sunday, May 25, 2014

Hi, this is the part two of the article where we are creating a complete AXIOM based web service with Axis2, If you haven't read the part one, please read it before going through this.

In this Post I will try to cover as much as possible regarding testing your webservice with SoapUI.

I will be using SoapUI 5.0 installed on top of Ubuntu 14.04.

Ok So lets begin.

What is SoapUI


SoapUI is a free tool that can be used to test web services.  SoapUI can test SOAP and REST based web services, JMS, AMF, as well as make any HTTP(S) and JDBC calls. Learn more from here.

Prerequisites


Install SoapUI on your PC, this can be done in two ways, Install SoapUI as a standalone Application or as a IDE plugin, I recommend to install this as a separate application.

Deploy your webservice created in part 1 and check whether it is deployed correctly as mentioned in that post.

Testing Your Service

Step 01

  1. Go to the Axis2 server URL and check whether the service is available. in my case the Axis2 services can be found at "http://localhost:8080/axis2/services/" 
  2. Click on the title of your service and you will be shown the WSDL of your service.


Note : The "wsdl" function following the service name will give you the WSDL of the service.

  1. Copy the url of the WSDL. 

Step 02

  1. Open SoapUI  and go to File >>> New SOAP Project.

  1. Then give an appropriate name to the project and paste the link of the WSDL of your service as shown in the following image and click OK.


  1. Now your project will be created with all service methods of your service. Note that Soap Binding 1.1 and 1.2 are automatically created by SoapUI.


  1. First lets test the "setProduct" method. Select the request which is located under setProduct method in the Soap1.1 Binding option as shown below.

  1. As you can see from the above image the full message or the payload that has to be sent to the service is not auto generated, as denoted by the "?" the necessary content has to placed in the marked position.
 Note that the message that the service expect is as following,


1
2
3
4
5
6
<tns:setProduct xmlns:tns="http://myshop.com/xsd">
   <tns:id>1</tns:id>
   <tns:model>Samsung</tns:model>
   <tns:price>100</tns:price>
   <tns:qty>6</tns:qty>
</tns:setProduct>

So lets add the required content to the correct place. make sure that your namespaces matches the namespaces defined in the service. The final message will look like following.


  1. Now click on the Submit Request button as shown in the above image. Nothing will be shown in the output window. :) Don't worry the service doesn't return anything so check the Axis2 console for any output. The Axis2 Console will show the following message if the request was successful.


The "setProduct" service is working fine now lets test the "getProduct" service.

  1. Now select the request of "getProduct" method and add the following SOAP content to the request. (make sure that you have already added the product you are going to query through setProduct method)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.televisionshop">
   <soapenv:Header/>
   <soapenv:Body>
     
         <!--Optional:-->
          <tns:getProduct xmlns:tns="http://myshop.com/xsd">
           <tns:id>001</tns:id>
          </tns:getProduct>
     
   </soapenv:Body>
</soapenv:Envelope>

Now click on Submit request button and the following output will be shown.



You have Successfully tested the web service you created, So in the next post I'll explain you how to write a simple client to access the service we created.

Thank for reading, and please feel free to drop a message or comment below if you have any issues. :)

0 comments:

Post a Comment

Subscribe to RSS Feed Follow me on Twitter!