Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Web Service interface test

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

Web service concept

Web service communicates in a way independent of platform and programming language. Web service is an interface that describes a set of operations that can be accessed on the network through standard XML message passing. It is based on the xml language protocol to describe the operation to be performed or to exchange data with another web service, a group of web applications defined as web services in the service-oriented architecture.

It can be understood simply that web service is a SOA (service-oriented programming) architecture, which does not depend on language or platform, and can communicate and call each other between different languages. Soap (simple object access Protocol) is the communication protocol of xml web service. When the user finds the WSDL (Web Service Description Language) document through UDDI, one or more operations of the web service established by SOAP call. Soap is the calling method specification in the form of xml document, which can support different underlying interfaces.

Web service API prepares if there is a ready-made webService, please ignore this step.

Use IDE tools such as Eclipse or Intellij to implement a simple web service in Java.

1. In File- > New- > Project in Intellij, select Maven to create the project. Enter the project name to create the project. We use WebService to name the project. After the project is created, there will be a file pom.xml in its directory, and the following configuration file will be automatically added:

WebService

WebService

1.0-SNAPSHOT

two。 Create a new java class under the java directory and define it as a webService interface with only methods and no concrete implementation.

Import javax.jws.WebMethod

@ javax.jws.WebService

Public interface WebService {

@ WebMethod

String sayHello (String name)

}

3. Then create a new java class in the same directory to implement the defined webService interface and overload the defined method in the interface.

@ javax.jws.WebService

Public class WebServiceImple implements WebService {

Public String sayHello (String name) {

System.out.println ("request succeeded")

String a = name+ "Hello world you are very good, congratulations!"

Return a

}

4. Create a new java class to launch our webService application

Import javax.xml.ws.Endpoint

Public class WebServicePublish {

Public static void main (String [] args) {

String address= "http://localhost:8989/WS_Server/Webservice";

Endpoint.publish (address,new WebServiceImple ())

System.out.println ("Server released successfully!")

}

}

5. Publish the application

Right-click execute to publish the application.

If normal, you can see the following information on the console:

/ Library/Java/JavaVirtualMachines/jdk1.8.0_161.jdk/Contents/Home/bin/java-Dfile.encoding=UTF-8 server released successfully!

Congratulations on your successful release, and then visit it directly from your browser.

Http://localhost:8989/WS_Server/Webservice?wsdl

Seeing a bunch of xml shows that webService can be accessed normally.

Web service interface test

WebService supports a relatively good tool SoapUI, which is for the soap protocol, we open SoapUI applications.

In the SoapUI toolbar, we select soap- > Create a New Soap Project, and in the pop-up box, we enter Project name and WSDL Link

Project Name: the recommended name is based on the project name

Initial WSDL: wsdl link to be tested

Create Requests: selected by default

Create TestSuite: test suites can be created by checking here or later.

Just click OK.

SoapUI automatically imports all interface information according to link

You can see the interface methods that SayHello makes us implement in Intellij.

In the request of SoapUI, enter the relevant information in the parameters to verify the interface.

Verify interfaces request and Response

At the same time, check whether there is an error message in Intellij IDE. The console shows that the request was successful.

From Response, we can judge that our return is consistent with what is defined in IDE.

Add TestSuite

The significance of adding TestSuite and TestCase is that soap interface testing provides basic scripting and regression verification for subsequent automated testing.

Right-click New TestSuite in webServiceTest

Create a new TestCase and right-click New TestCase in Suite

The last step is to add the interface to the TestCase, right-click the interface SayHello, select Add to TestCase, and then select to add Suite and TestCase to add the interface to the Step.

In this way, the SayHello interface is added to the testCase, which is very convenient. At this time, you can add related assertions to the interface SayHello.

Today's recommended reading articles are recommended

Why do interface testing?

JMeter database operation

Jmeter Interface Test-regular expression

JMeter returns garbled code in Chinese

Jmeter interface testing-parameterization

JMeter Interface testing-Basics

Test-impression

Add Wechat to the consulting work

scan a QR code

Welcome self-recommendation and recommendation, need Wechat to push resume!

Please poke the QR code below to learn more.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report