Вы находитесь на странице: 1из 5

Web Services Testing

What is WebService?

Web Services is the mechanism or the medium of communication through which two
applications / machines will exchange the data irrespective of their underline
architecture and the technology.

Why is WebService Needed?

In general, software applications are developed to be consumed by the human


beings, where a person sends a request to a software service which in-turn returns a
response in human readable format.

In the modern era of technology if you want to build a software application you don't
need to build each and everything from scratch. There are lots of readymade
services available which you can plug into your application and you can start
providing those services in your application.

For example you want to display weather forecast information you don't need to
collect, process and render the data in your application. You can buy the services
from the people who already well-established in processing and publishing such kind
of data.

Web services allow us to do these kind of implementations.

This WebService can be called by a Software Application using SOAP or HTTP


protocol.

Web Services can be implemented in different ways, but the following two are the
popular implementations approaches.

1. SOAP (Simple Object Access Protocol)


2. REST (Representational State Transfer architecture)
SOAP
SOAP is a standard protocol defined by the W3C Standard for sending and
receiving web service requests and responses.

SOAP uses the XML format to send and receive the request and hence the data
is platform independent data. SOAP messages are exchanged between the provider
applications and receiving application within the SOAP envelops.

As SOAP uses the simple http transport protocol, its messages are not got blocked
by the firewalls.

Download soapui from the site : https://www.soapui.org/downloads/soapui.html

http://www.webservicex.com/globalweather.asmx?WSDL

WSDL – Web services description language

REST

REST means Representational State Transfer; it is an architecture that generally


runs over HTTP. The REST style emphasizes the interactions between clients and
services, which are enhanced by having a limited number of operations. REST is an
alternative to SOAP (Simple Object Access Protocol) and instead of using XML for
request REST uses simple URL in some cases. Unlike SOAP, RESTFUL
applications uses HTTP build in headers to carry meta-information.

There are various code that REST use to determine whether user has access to API
or not like code 200 or 201 indicates successful interaction with response body while
400 indicates a bad request or the request URI does not match the APIs in the
system. All API request parameters and method parameters can be sent via
either POST or GET variables.

Rest API supports both XML and JSON format. It is usually preferred for Mobile and
web apps as it makes app work faster and smoother

public class NetClientGet {


public static void main(String[] args) throws Exception {
URL url = new URL("http://services.groupkt.com/state/get/IND/UP");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");

/* if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}*/

BufferedReader br = new BufferedReader(new


InputStreamReader((conn.getInputStream())));
String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
}

//Post request

public class Rest_PostRequest {

public static void main(String[] args) throws Exception {


try {
URL url = new
URL("http://localhost:8080/RESTfulExample/json/product/post");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");

String input = "{\"qty\":100,\"name\":\"iPad 4\"}";

OutputStream os = conn.getOutputStream();
os.write(input.getBytes());
os.flush();

if (conn.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
throw new RuntimeException("Failed : HTTP error code : "
+ conn.getResponseCode());
}

BufferedReader br = new BufferedReader(new


InputStreamReader((conn.getInputStream())));

String output;
System.out.println("Output from Server .... \n");
while ((output = br.readLine()) != null) {
System.out.println(output);
}
conn.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
}
}
}

API vs Web Service


API and Web service serve as a means of communication. The only
difference is that a Web service facilitates interaction between two
machines over a network. An API acts as an interface between two
different applications so that they can communicate with each other. An
API is a method by which the third-party vendors can write programs
that interface easily with other programs. A Web service is designed to
have an interface that is depicted in a machine-processable format
usually specified in Web Service Description Language (WSDL).
Typically, “HTTP” is the most commonly used protocol for
communication. Web service also uses SOAP, REST, and XML-RPC as
a means of communication. API may use any means of communication
to initiate interaction between applications. For example,
the system calls are invoked using interrupts by the Linux kernel API.
An API exactly defines the methods for one software program to
interact with the other. When this action involves sending data over a
network, Web services come into the picture. An API generally involves
calling functions from within a software program.
In case of Web applications, the API used is web based. Desktop
applications such as spreadsheets and word documents use VBA and
COM-based APIs which don’t involve Web service. A server application
such as Joomla may use a PHP-based API present within the server
which doesn’t require Web service.
Read more: Difference Between API and Web Service | Difference
Between http://www.differencebetween.net/technology/internet/diffe
rence-between-api-and-web-service/#ixzz57eJ8PMHU

https://www.guru99.com/webservice-testing-beginner-guide.html

https://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

https://www.mkyong.com/webservices/jax-rs/restfull-java-client-with-java-net-url/

https://dzone.com/articles/restful-web-services-java

http://www.groupkt.com/post/f2129b88/free-restful-web-services-to-consume-and-test.htm

http://www.groupkt.com/post/c9b0ccb9/country-and-other-related-rest-webservices.htm

https://www.javatpoint.com/web-services-tutorial

https://stackoverflow.com/questions/10926353/how-to-read-json-file-into-java-with-simple-json-library

http://www.differencebetween.net/technology/internet/difference-between-api-and-web-service/

Вам также может понравиться