Web Service Sample Project & Testing

In this tutorial, we are going to develop a beginner’s level Web Service sample project testing using SOAP protocol for both RPC and Document style and after that, we will learn how to test it. Later in this tutorial series, we will learn about Web services based on the REST protocol.

Web Service Sample Project: (SOAP Protocol):

  • SOAP is an XML based protocol.
  • The full form of SOAP is the Simple Object Access Protocol.
  • In order to communicate between two applications in cross-platforms SOAP is a W3C recommendation.
  • SOAP is both platform and programming language independent protocol.
Web Service Testing Sample Project
Web service sample project testing

Software Requirements: Below are the basic requirements to build a Web service project in JAVA.

  • Jre1.8.0_25 as JAVA runtime environment.
  • Eclipse IDE as development tool.
  • A standard HTTP browser like Chrome, etc. This will help to view WSDL.

Project on SOAP Web Service using Document Style:

The project file for SOAP Web Service as “webservice-project-doc-style” can be downloaded from here. Below are the steps and explanations to run the SOAP Web Service.

  1. Firstly, create a JAVA interface that has a business method definition in it. In order to associate this interface with Webservice, use annotations “@WebService” and “SOAPBinding (style=Style.DOCUMENT) ” as I have demonstrated in the project.
  2. Secondly, create a class implementing the above interface and its business method. Similarly, in order to associate it with Webservice, use annotations “@WebService with endpoint interface location” and “SOAPBinding (style=Style.DOCUMENT)” as demonstrated in the project.
  3. Thirdly, publish this web service to expose the business logic.
  4. Once published, WSDL can be obtained at this link. http://localhost:8074/web?wsdl
  5. Now create a client class through which this service business method can be obtained to execute the business logic. Web Service client class uses the above WSDL URL to access WSDL and then obtains the qualifying name for the target namespace and web service name. Using both service method port is accessed and this is the procedure to call the web service as a client.

All above steps are demonstrated in the Web Service project for DOCUMENT style.

Project on SOAP Web Service using RPC Style:

Attached project file for SOAP Web Service as “webservice-project-rpc-style” which can be downloaded from here. Below are the steps and explanations to run the SOAP Web Service.

  • Firstly, create a JAVA interface that has a business method definition in it. In order to associate this interface with Webservice use annotations “@WebService” and “SOAPBinding (style=Style.RPC)”.
  • Secondly, create a class implementing the above interface and its business method. Similarly in order to associate it with Webservice use annotations “@WebService with endpoint interface location” and “SOAPBinding (style=Style.RPC)”.
  • Thirdly, publish this web service to expose the business logic.
  • Once published, WSDL can be obtained at this link. http://localhost:8075/web?wsdl
  • Now create a client class through which this service business method can be obtained to execute the business logic. Web Service client class uses the above WSDL URL to access WSDL and then obtains the qualifying name for the target namespace and web service name. Using both service method port is accessed and this is the procedure to call the web service as a client.
  • All the above steps are demonstrated in the Web Service project for RPC style.

RPC Style WSDL:

[Click below image to enlarge]

RPC Style WSDL

Document Style WSDL:

[Click below image to enlarge]

Document Style WSDL

Comparison between Document and RPC Style:

PropertiesRPC StyleDocument Style
DescriptionRPC Style generates the XML structure using method name and parameters.Document Style uses single XML document with XSD schema for its validation.
WSDL validationWSDL generated here is difficult to get validated against schema.WSDL generated can be validated against preferred schema with ease.
SOAP MessageSOAP message is sent as many elements in RPC style Web service.SOAP message is sent as a single document in Document style Web service.
Coupling complexitiesIt is tightly coupledIt is loosely coupled.
Operation nameIn RPC style Web services, SOAP message keeps the operation name.In Document Style Web Services, SOAP messages lose the operation name.
ParametersParameters are sent as discrete values.Parameters are sent in XML format.
WSDL file information about typesIt does not specifies any information about types (namespaces and schemaLocation)It specifies details about namespaces and schemaLocation
Message Part BodyIt defines name and type attributes in WSDL file for message part body.It defines name and element attributes in WSDL file for message part body.
Soap BodyIt defines use and namespace attributes in saop: body.It defines use attributes only, no namespaces are defined in saop: body.
WSDL snapshotsRPC style WSDL added above for comparison.Document style WSDL added above for comparison.

Pros and Cons of SOAP Web Service:

Pros:

  • SOAP is highly secured as it has its own inbuilt security known as WS Security.
  • As discussed above, SOAP Web service can be build using any programming language like .Net, JAVA, etc. and be executed across cross-platforms.

Cones:

  • Since SOAP web Services are XML based format, therefore there is a need to read and parse XML documents. On top of this, there are so many defined standards that must be obeyed while building such Web services. This slows down the operation of SOAP Web Services and occupies more bandwidth and resources.
  • WSDL is the only mechanism to locate SOAP Web Service. Therefore it is not very flexible.

Over to you:

In the above tutorial we learnt about how to build SOAP Web services using both styles RPC and DOCUMENT style. Now next in this tutorial we will discuss about the web service testing.

Web Service Testing: In the last tutorials, we discussed the SoapUI tool which is used to test the web services and Web APIs and the testing steps which are actually involved in the web services testing. Here, we are going to discuss those steps in detail with the help of the above sample Web Service project.

  • WSDL file definition understanding: Once WDSL is created using web services, test cases are written to test for the required standards present in WSDL like which style it is? Does it cover all the required input parameters? What is the datatype for those input parameters? etc.
  • Operations provided by the Web Service: Test cases covering the required operations which are present in the web Service for which it was developed. Does it cover the required business logic in the correct way?
  • XML Request message format that sent as SOAP request message: Test cases covering the input data, data type, boundary condition validations, stack overflow validations, functional test cases, etc.
  • XML Response message format received as SOAP response message: Test cases covering the output data and its type, output data validations, stack overflow validations, security test, functional test cases, etc.
  • A simple local tool or test program that could send XML message request and receive the request as an XML message response: This refers to the fact that in order to test the web service, we need to develop a client program through which we can send input data as request and test on the output data received as a response.

These are the fundamental testing aspects to test any Web service, no matter which style it is written into. In our next tutorial series we are going to discuss on how to test WebService using SoapUI tool. Also for which we will first learn to install and configure SoapUI tool.

In next article we are going to cover “Tutorial 4 – Installation and configuration of SoapUI“.

SoapUI Tutorial Series

⇓ Subscribe Us ⇓


If you are not regular reader of this website then highly recommends you to Sign up for our free email newsletter!! Sign up just providing your email address below:


 

Check email in your inbox for confirmation to get latest updates Software Testing for free.


  Happy Testing!!!
 

Leave a Comment

Share This Post