Categories

Netsparker Web Application Security Scanner

Web Service Sample Project & Testing

In this tutorial, we are going to develop beginner’s level Web Service sample project 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 REST protocol.

Web Service Sample Project: (SOAP Protocol):

  • SOAP is a XML based protocol.
  • Full form of SOAP is Simple Object Access Protocol.
  • In order to communicate between two applications in cross-platforms SOAP is 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:

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

    1. Firstly, create a JAVA interface which has 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 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 webservice 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 above WSDL URL to access WSDL and then obtains the qualifying name for 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 explanation to run the SOAP Web Service.

  • Firstly, create a JAVA interface which has 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 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 webservice 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 above WSDL URL to access WSDL and then obtains the qualifying name for 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 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:

Properties RPC Style Document Style
Description RPC Style generates the XML structure using method name and parameters. Document Style uses single XML document with XSD schema for its validation.
WSDL validation WSDL generated here is difficult to get validated against schema. WSDL generated can be validated against preferred schema with ease.
SOAP Message SOAP message is sent as many elements in RPC style Web service. SOAP message is sent as a single generic modafinil available in us document in Document style Web service.
Coupling complexities It is tightly coupled It is loosely coupled.
Operation name In RPC style Web services, SOAP message keeps the operation name. In Document Style Web Services, SOAP messages loses the operation name.
Parameters Parameters are sent as discrete values. Parameters are sent in XML format.
WSDL file information about types It does not specifies any information about types (namespaces and schemaLocation) It specifies details about namespaces and schemaLocation
Message Part Body It 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 Body It defines use and namespace attributes in saop: body. It defines use attributes only, no namespaces are defined in saop: body.
WSDL snapshots RPC 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 which 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 about 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 on those steps in detail with the help of above sample Web Service project.

  • WSDL file definition understanding: Once WDSL is created using web services, tests cases are written to test for the required standards present in WSDL like which style it is? Does it covers all the required input parameters? What are 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 request as XML message response: This refers to the fact that in order to test the WebService, we need to develop a client program through which we can send input data as request and test on the output data received as 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“.

Happy Testing!!!

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>