SOAPUI访问WEBSERVICE案例

时间:2022-07-28
本文章向大家介绍SOAPUI访问WEBSERVICE案例,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

小编最近被要求测试一下webservice接口,于是小编jmeter和postman轮番编码+运行循环了N次,各种网上搜解决方案,倒腾半天无果,于是小编果断放弃!然后找了这个好用的工具—soapui,于是柳暗花明啦。

为了让小伙伴简单明了的了解一下如何使用,小编就找个webservice的案例,然后通过soapUI工具来测试,抛砖引玉开始 ... …

小注:本案例基于maven项目,eclipse里搭建maven的javaweb项目的解决方案,请关注“IT测试前沿”公众号,历史文章里搜索

一、搭建基于maven项目的javaWeb工程,项目结构如图

二、pom.xml配置文件

<!-- spring3 -->

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-core</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-context</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-jdbc</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-beans</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-web</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-expression</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-orm</artifactId>

            <version>3.1.2.RELEASE</version>

        </dependency>

        <!-- spring web -->

        <dependency>

            <groupId>org.springframework</groupId>

            <artifactId>spring-web</artifactId>

            <version>2.5.5</version>

        </dependency>

        <dependency>

            <groupId>commons-logging</groupId>

            <artifactId>commons-logging</artifactId>

            <version>1.1</version>

        </dependency>

        <dependency>

            <groupId>javax.xml</groupId>

            <artifactId>jaxb-api</artifactId>

            <version>2.1</version>

            <type>pom</type>

        </dependency>

        <dependency>

            <groupId>javax.xml</groupId>

            <artifactId>jaxb-impl</artifactId>

            <version>2.1</version>

        </dependency>

        <dependency>

            <groupId>xfire</groupId>

            <artifactId>saaj-api</artifactId>

            <version>1.3</version>

        </dependency>

        <dependency>

            <groupId>xfire</groupId>

            <artifactId>saaj-impl</artifactId>

            <version>1.3</version>

        </dependency>

        <dependency>

            <groupId>wsdl4j</groupId>

            <artifactId>wsdl4j</artifactId>

            <version>1.6.2</version>

        </dependency>

        <dependency>

            <groupId>org.apache.cxf</groupId>

            <artifactId>cxf-rt-frontend-jaxws</artifactId>

            <version>2.2.3</version>

        </dependency>

        <dependency>

            <groupId>org.apache.cxf</groupId>

            <artifactId>cxf-rt-transports-http</artifactId>

            <version>2.2.3</version>

        </dependency>

        <dependency>

            <groupId>org.apache.cxf</groupId>

            <artifactId>cxf-rt-transports-http-jetty</artifactId>

            <version>2.2.3</version>

        </dependency>

配置完成----Run as—Maven Build,jar就下载下来了,图片仅仅截了部分

三、code开始

Lshtest.java

//接口 @WebService publicinterface Lshtest { //方法名 String sayHello(@WebParam(name = "userName") String userName); }

LshtestImpl.java

//接口实现 @WebService(serviceName = "HelloWorld") publicclass LshtestImpl implements Lshtest { @Override public String sayHello(@WebParam(name = "userName") String userName) { System.out.println("客户端输入信息:" + userName); return"this is my fisrt webservice demo " + userName; } }

myListener.java

publicclass myListener implements ServletContextListener { @Override publicvoid contextDestroyed(ServletContextEvent arg0) { } @Override publicvoid contextInitialized(ServletContextEvent arg0) { System.out.println("启动Tomcat..."); ClassPathXmlApplicationContext act = new ClassPathXmlApplicationContext( "此处为绝对地址** /WEB-INF/applicationContext.xml"); } }

Web.xml

<web-app> <display-name>Archetype Created Web Application</display-name> <listener> <listener-class>wb.myListener</listener-class> </listener> </web-app>

Spring配置文件

<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:jaxws="http://cxf.apache.org/jaxws" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd"> <jaxws:endpoint id="ProjectManager" implementor="wb.LshtestImpl" address="http://localhost:8081/Lshtest" /> </beans>

四、启动tomcat

启动成功

浏览器中输入地址:http://localhost:8081/Lshtest?wsdl

五、新建soapUI工程

六、测试soapui,成功返回

查看控制台输出