banner



How To Write Simple Web Service In Go

What is WebService?

Web Services is the mechanism or the medium of communication through which ii applications / machines will commutation the data irrespective of their underline architecture and the engineering.

What is Spider web Service Testing?

Web Services Testing is a type of software testing that validates Spider web services. The purpose of Web Services Testing is to check the functionality, reliability, performance, and security of an API(Application Program Interface). Web Service Testing is similar to unit of measurement testing in some cases. You can test a Webservice manually or create your own automation code or use an off-the shelf automation tool like Postman.

Why is WebService Needed?

In general, software applications are developed to be consumed by the human beings, where a person sends a asking to a software service which in-turn returns a response in human readable format.

In the modern era of technology if you lot 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 tin can plug into your application and you can start providing those services in your application.

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

Spider web services permit us to do these kind of implementations.

Every bit an instance, consider the following WebService

http://world wide web.webservicex.net/stockquote.asmx?op=GetQuote

It gives Share Value for a Visitor.

Let's find share price for Google (Symbol: GOOG )

Web Service Testing: A Beginner's Tutorial

The response XML gives the stock cost.

Web Service Testing: A Beginner's Tutorial

This WebService can be chosen by a Software Awarding using SOAP or HTTP protocol.

Spider web Service Protocols

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

  1. Soap (Simple Object Admission Protocol)
  2. Remainder (Representational Country Transfer architecture)

Lather

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 transport and receive the request and hence the data is platform independent information. Lather messages are exchanged between the provider applications and receiving awarding within the SOAP envelops.

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

Residuum

REST ways REpresentational Land Transfer; it is an architecture that generally runs over HTTP. The Balance 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 asking REST uses uncomplicated URL in some cases. Unlike Lather, RESTFUL applications uses HTTP build in headers to carry meta-data.

In that location are diverse lawmaking that Balance utilize to determine whether user has admission to API or not similar lawmaking 200 or 201 indicates successful interaction with response trunk while 400 indicates a bad request or the request URI does non lucifer the APIs in the system. All API request parameters and method parameters tin can exist sent via either POST or Become variables.

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

WSDL

WSDL (Web Services Clarification Linguistic communication) is an XML based language which will be used to describe the services offered by a web service.

WSDL describes all the operations offered by the particular web service in the XML format. It also defines how the services can be called, i.e what input value we have to provide and what will be the format of the response it is going to generate for each kind of service.

How to examination a Spider web Service?

To test web service, you tin can

  1. Test Manually
  2. Create your own Automation Code
  3. Use an off-the shelf automation tool like SoapUI.

Web Services Automation Testing involves following steps –

  1. Empathize the WSDL file
  2. Determine the operations that detail web service provides
  3. Determine the XML request format which nosotros need to transport
  4. Make up one's mind the response XML format
  5. Using a tool or writing code to send request and validate the response

Suppose we want to test web service which provides Currency Conversion Facility. It will the current conversion rates between the different countries currency. This service we can use in our applications to convert the values from i currency to the other currency.

Now lets look at in a higher place steps

Step 1 to 4: Understanding WSDL and determining operations & XML formats

Currency Convertor WSDL file tin be seen @ (http://www.webservicex.internet/CurrencyConvertor.asmx?wsdl) which will give the information about the Currency Convertor web service methods which it volition support, the parameter which nosotros demand pass and the type of parameters… etc.

Web Service Testing: A Beginner's Tutorial

Web Service Testing: A Beginner's Tutorial

Step 5: Using a tool or writing lawmaking to send request and validate the response

At that place are lots of WebService Examination tools available to test Lather web service. SoapUI is one of the popular API tool which will aid the states to test SOAP spider web services. In fact you can utilise the any programing linguistic communication which is capable of sending the XML request to the spider web service provider awarding over the http and able to parse and validate the response XML against the expected result. In this Web Services Testing tutorial, we volition examination the WebService

  1. Using Java
  2. Using SoapUI

PART ane) WebService Testing Using Apache Axis2 API (Coffee).

Mostly web service takes the request and sends the response in the XML format.

Apache Axis2 API projection is a Java implementation API, which will be used to create the Spider web services for both server side (service provider) and customer side (service consumer).

Axis2 is capable of sending Soap letters and Receives & Processes the SOAP letters. We can write a small Java plan using the API to create the web service. Axis2 will generate the WSDL from Java program which will be used to communicate the services offered past the web service. We can use the same Axis2 to generate the Coffee class (stub) from WSDL file which we tin can employ as a client program to generate the web service asking, to transport the request to the service end betoken and to procedure the response.

  1. Basically nosotros will create a unproblematic Java programme in which we volition instantiate the stub class.
  2. Using the stub we will invoke the request method past passing all the required information.
  3. Stub programme volition convert that asking into XML request format and sends it the service end point which will read the request and processes the request and sends the response in XML format.
  4. The XML response will be converted into Coffee course by stub and returned to the actual plan.

Let's await at above steps in detail

Step a) Download the axis2 API @ https://axis.apache.org/axis2/Java/cadre/download.cgi & Prepare the environs variable 'AXIS2_HOME'

Web Service Testing: A Beginner's Tutorial

Step b) Create a folder to go on all the generated artifacts

Ex : C:\Axis\Projects\CurrencyConverter

Step c) Open the control prompt and navigate to the folder structure where you lot want to generate the artifacts and Run the following command which volition generate the stubs

%AXIS2_HOME%\bin\WSDL2Java -uri http://www.webservicex.net/CurrencyConvertor.asmx?wsdl -p org.apache.axis2.currencyconvertor -d adb –s

Web Service Testing: A Beginner's Tutorial

Step d) Once the command is successfully run, you will see the binder with required files.

Web Service Testing: A Beginner's Tutorial

Stride e)In the next step of this Spider web Services Testing tutorial, nosotros take to create the client program, through which nosotros will transport the bodily request using the generated stubs. Open up the eclipse and create the new Java project and select the binder which we have created above.

Web Service Testing: A Beginner's Tutorial

Step f) Add all the axis2 related jars to project build path, which will be in that location in lib binder of the axis2 software folder

(for ex : C:\Axis\axis2-1.6.2\lib)

Web Service Testing: A Beginner's Tutorial

Step 1000) Create a new Java class (ex : Customer.Coffee) and instantiate stub object. Using the stub object we can call all the supported methods of the detail WebService.

Web Service Testing: A Beginner's Tutorial

Client.Java Programme package org.apache.axis2.currencyconvertor; import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.ConversionRate; import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.ConversionRateResponse; import org.apache.axis2.currencyconvertor.CurrencyConvertorStub.Currency;  public class Customer {  public static void main(Java.lang.Cord args[]) {    try {         //Create the stub object past passing the service terminate point url        CurrencyConvertorStub stub = new CurrencyConvertorStub("http://www.webservicex.net/CurrencyConvertor.asmx");        //ConversionRate is the form which we take to apply mention the from and to currency        //ConversionRate object will be the parameter for the conversionRate operation        ConversionRate conversionRate = new ConversionRate();        conversionRate.setFromCurrency(Currency.USD);        conversionRate.setToCurrency(Currency.INR);         //Create the ConversionRateResponse object, which is going to be used to catch the response        //call the conversionRate service using the stub object        ConversionRateResponse conversionRateResponse = stub.conversionRate(conversionRate);         //We tin utilise the conversionRateResponse object to retrieve the response of the ConversionRate Service        System.out.println("Conversion Rate from INR to USD : " + conversionRateResponse.getConversionRateResult());         } grab (Exception e) {        e.printStackTrace();       }     } }          

Part two) How to Test Using SoapUI Spider web Service

In SoapUI

  1. Go to File > New Soap Project
  2. Enter the project Name and the WSDL URI location
  3. Click OK

Web Service Testing: A Beginner's Tutorial

  1. Aggrandize the kickoff request and double click on the 'Request1'. It volition brandish the SOAP request in the XML format.
  2. Enter the From Currency and To Currency
  3. Click on the submit push
  4. Response XML volition exist displayed right side pane.

Web Service Testing: A Beginner's Tutorial

Equally you may conclude, usage of WebService Test tools similar SoapUI expedites your Web Services Automation Testing Endeavor. Hence SoapUi will exist focus of our learning in the succeeding tutorials.

Summary

  • Software Applications communicate and exchange data with each other using a WebService
  • SOAP and REST are ii popular protocols to create a WebService
  • SOAP supports XML based data commutation
  • REST support XML, Json or exchange of data in elementary URL for WebServices API Testing.
  • WSDL is XML based language which will be used to describe the services offered by a web service. SOAP is defined using WSDL.
  • To test WebService you lot tin

    • Create your own code. For instance employ Axis2 API for Java
    • Use WebService Test Automation tools like SoapUI
  • Automation Tools like SoapUI will jumpstart your Spider web Services Automation Testing efforts, volition require less coding effort compared to creating your own code using Axis2 API

FAQ

What is Difference between WebService and WebAPI?

Web Service Web API
  • Defined past W3C, all advice & information exchange is based on XML
  • Web API communication & information exchange could be XML, JSON or plain data
  • It has defined standards – WSDL
  • No defined standard
  • You lot cannot compress the data only you tin can compress the HTML request
  • You can shrink the data
  • Example: SOAP
  • Example: Residue

Larn more about Web API Testing

This Spider web Services Testing tutorial is made possible with contributions of Mr. Narender Reddy Nukala

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

Posted by: heathhichit.blogspot.com

0 Response to "How To Write Simple Web Service In Go"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel