对于想了解基于WebService的性能测试脚本开发的读者,本文将提供新的信息,我们将详细介绍webservice测试工具,并且为您提供关于PHP使用SOAP扩展实现WebService的方法webs
对于想了解基于WebService的性能测试脚本开发的读者,本文将提供新的信息,我们将详细介绍webservice 测试工具,并且为您提供关于PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice、soapUI 做webservice的性能测试、WebService - Axis2基于JAX-WS开发WebService并发布多个WebService、webservice soap简单的性能测试结论的有价值信息。
本文目录一览:- 基于WebService的性能测试脚本开发(webservice 测试工具)
- PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice
- soapUI 做webservice的性能测试
- WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
- webservice soap简单的性能测试结论
基于WebService的性能测试脚本开发(webservice 测试工具)
本文以一个基于webservice的文件下载功能服务为例,运用Loadrunner 11 对其进行性能测试脚本开发和调试,具体操作流程如下所示:
首先,选择WebService协议进行脚本录制。
点击“Manage Service”按钮,然后选择“Import”。在Importservicre中的URL导入一个WSDL服务的文本http://wsefrst.paerswft.com/store-01.wsdl,点击“Import”。其中,WSDL描述WebService的公共接口。这是一个基于XML的关于如何与Web服务通讯和使用的服务描述,也就是描述与目录中列出的WebService进行交互时需要绑定的协议和信息格式。通常采用抽象语言描述该服务支持的操作和信息,使用的时候再将实际的网络协议和信息格式绑定给该服务。
因此在Loadrunner在WebService虚拟用户协议中也支持两种测试方式:一种是通过“Add Service Call”的方式,此功能导入的是WSDL文件;一种是通过Import SOAP的方式,Import SOAP的方式需要导入定义好的XML请求文件。在本文中应用前一种导入WSDL文件的方式。
下面对被测服务进行参数化,点击“Add Service Call”选择调用接口,对WSDL文件中的参数,进行参数化赋值和选择相应动作。如下图,在选择相应的测试机service后,这里选择“down”下载这个动作,并进行参数化赋值。关于参数化赋值方法,可以勾选住“Include argument in”在“Vaule”输入框中进行常量赋值和变量参数化,变量参数化点击蓝色“ABC”即可,同时可以生成运行脚本,本文针对guid进行参数化,生成2个脚本,一个是guid=111的常量参数化,一个是guid={guid}的变量参数化操作。对guid变量参数化,参数策略为select next row:Unique,Update value on:Each iteration。其中, GUID即Globally Unique Identifier(全球唯一标识符)。GUID是一个通过特定算法产生的二进制长度为128位的数字标识符,用于指示产品的唯一性。
具体脚本如下所示:
Action()
{
web_service_call( "StepName=down_101",
"SOAPMethod=T9EsbServiceService|T9EsbService|down",
"ResponseParam=response",
"Service=T9EsbServiceService",
"ExpectedResponse=SoapResult",
"Snapshot=t1344414497.inf",
BEGIN_ARGUMENTS,
"guid=111",
END_ARGUMENTS,
BEGIN_RESULT,
END_RESULT,
LAST);
web_service_call( "StepName=down_102",
"Snapshot=t1344414875.inf",
"guid={guid}",
LAST);
return 0;
}
PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice
soapUI 做webservice的性能测试
测试工具 soapui
WebService - Axis2基于JAX-WS开发WebService并发布多个WebService
前两篇关于使用Axis2开发WebService,都是使用了services.xml文件,而且还要拷贝axis2.war下面的文件到项目中,实际开发中是很麻烦的。
本篇简要讲述如何基于JAX-WS开发WebService的服务端,客户端如何调用请参考前几篇文章。
【1】编写接口与实现类
接口类如下:
package com.web.service; import javax.jws.WebMethod; import javax.jws.WebService; import javax.jws.soap.soAPBinding; @WebService @SOAPBinding(style = SOAPBinding.Style.RPC) public interface MyService { @WebMethod public String sayHello(String name); }
实现类如下:
package com.web.service.impl; import javax.jws.WebService; import javax.jws.soap.soAPBinding; import com.web.service.MyService; @WebService @SOAPBinding(style = SOAPBinding.Style.RPC) public class MyServiceImpl implements MyService{ @Override public String sayHello(String name) { System.out.println("this is wsservice "+name); return "hello "+name; } }
【2】xml配置
因为没有与Spring耦合,所以不需要对Spring进行配置。
需要的xml配置如下:
① 在WEB-INF下建立sun-jaxws.xml
<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0"> <endpoint name="wsService" implementation="com.web.service.impl.MyServiceImpl" url-pattern="/services/wsService" /> </endpoints>
该xml中只有一个endpoints元素,该元素下可以有多个endpoint ,每个endpoint 对应一个WebService,也就是说,可以发布多个WebService。
② 修改web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <listener> <listener-class> com.sun.xml.ws.transport.http.servlet.WSservletcontextlistener </listener-class> </listener> <servlet> <servlet-name>wsService</servlet-name> <servlet-class> com.sun.xml.ws.transport.http.servlet.WSServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>wsService</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> <welcome-file>index.html</welcome-file> </welcome-file-list> </web-app>
或者web.xml如下:
<servlet> <display-name>Apache-Axis Servlet</display-name> <servlet-name>AxisServlet</servlet-name> <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>AxisServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping>
如果说与Spring整合,那么只需要加入spring配置即可:
<context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>
【3】引入jar
没错,这个超级重要。不是说,没有jar不行,这里强调的是,你可能会遇到这种奇葩的找不到类的问题。
比如,这个类org/glassfish/gmbal/ManagedobjectManager
,是不是没见过?
然后去找,有的说,你只需要引入以下依赖就行了。
<dependencies> <!-- JAXWS-RI --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>2.2.10</version> </dependency> </dependencies>
扯,扯,扯,可能对他真有用,但可能对你无济于事。
继续百度,有的说,需要management-api.jar。
怎么说呢,这个jar真心不好找,你可以试试。
即使,幸运,找到了,你以为就完了?
然而,并没有,还会有其他的类找不到。。。
幸运的是,遇到了我,下面是需要的jar与pom文件
这是服务端的jar截图,有些你可能不需要。
pom.xml如下:
<properties> <axis2.version>1.6.2</axis2.version> <jaxws.version>2.2.10</jaxws.version> </properties> <!-- axis2 包 --> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-kernel</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-http</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-transport-local</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-adb-codegen</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-codegen</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-java2wsdl</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-json</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-Metadata</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-spring</artifactId> <version>${axis2.version}</version> </dependency> <dependency> <groupId>org.apache.axis2</groupId> <artifactId>axis2-xmlbeans</artifactId> <version>${axis2.version}</version> </dependency> <!-- JAXWS 包 --> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-rt</artifactId> <version>${jaxws.version}</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>jaxws-tools</artifactId> <version>${jaxws.version}</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>rt</artifactId> <version>${jaxws.version}</version> </dependency> <dependency> <groupId>com.sun.xml.ws</groupId> <artifactId>policy</artifactId> <version>2.3.1</version> </dependency> <dependency> <groupId>org.glassfish.gmbal</groupId> <artifactId>gmbal-api-only</artifactId> <version>3.0.0-b023</version> </dependency> <dependency> <groupId>org.glassfish.gmbal</groupId> <artifactId>gmbal-api-only</artifactId> <version>3.0.0-b023</version> </dependency>
还有一点,请使用中央仓库下载,因为最后面几个阿里云仓库根本没有,坑死我了!
温馨提示 : 上面的jar可能对你项目不完整,不过几个难缠的已经包括在内,其他的按需自行添加!
【4】发布Tomcat测试
正常启动如下图:
wsdl地址:
http://localhost:8080/Axis2WS/services/wsService?wsdl
就是你的正常项目访问路径+xml中配置的address+?wsdl
浏览器显示如下:
【5】客户端测试
① 根据wsdl,生成Stub到项目下。
② 编写客户端代码如下:
package com.web.client2; import com.web.client2.MyServiceImplServiceStub.SayHello; import com.web.client2.MyServiceImplServiceStub.SayHelloResponse; public class Client { public static void main(String[] args) throws Exception { MyServiceImplServiceStub factory = new MyServiceImplServiceStub(); SayHello sayHello = new SayHello(); sayHello.setArg0("Tom"); SayHelloResponse response = factory.sayHello(sayHello ); String result = response.get_return(); System.out.println("Client "+result); } }
客户端输出结果如下:
服务端输出结果如下:
Client使用RPC方式如下:
package com.web.client; import javax.xml.namespace.QName; import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.EndpointReference; import org.apache.axis2.client.Options; import org.apache.axis2.rpc.client.RPCServiceClient; public class Client { public static void main(String[] args) { String url="http://localhost:8080/Axis2WS/services/wsService?wsdl"; String method="sayHello"; RPCServiceClient serviceClient; try { serviceClient = new RPCServiceClient(); Options options = serviceClient.getoptions(); EndpointReference targetEPR = new EndpointReference(url); options.setTo(targetEPR); QName opAddEntry = new QName("http://impl.service.web.com/","sayHello"); Object[] opAddEntryArgs = new Object[] {"Tom"}; Class[] classes = new Class[] {String.class }; Object[] result=serviceClient.invokeBlocking(opAddEntry,opAddEntryArgs,classes); System.out.println(result[0].toString()); } catch (AxisFault e) { // Todo Auto-generated catch block e.printstacktrace(); } } }
【6】多个WebService
就像上面说的一样,在sun-jaxws.xml中进行配置。
演示如下:
① 拷贝MyServiceImpl并重命名为MyServiceImpl2
② 修改sun-jaxws.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <endpoints xmlns="http://java.sun.com/xml/ns/jax-ws/ri/runtime" version="2.0"> <endpoint name="wsService" implementation="com.web.service.impl.MyServiceImpl" url-pattern="/services/wsService" /> <endpoint name="wsService2" implementation="com.web.service.impl.MyServiceImpl2" url-pattern="/services/wsService2" /> </endpoints>
此时,第二个WebService对应wsdl地址为:
http://localhost:8080/Axis2WS/services/wsService2?wsdl
浏览器显示如下:
不用拷贝文件,不用配置services.xml是不是很爽?!
webservice soap简单的性能测试结论
因为最近要推行用webservice soap来实现多语言的调用的服务,所以对soap进行一个简单的压力测试,就是一句简单的字符串传输和一个简单的对象传输返回。
简单的压测,结果并不尽如人意,在100M的带宽(局域网内的两台机器),跑满了带宽每秒的调用数就是2000多而已。如果没有对比,或许我不会不满意,但是,由于之前公司部分架构是采用alibaba的rpc框架dubbo进行开发soa服务的,我当时简单的测试下,同样的100M带宽同样的测试内容,dubbo可以达到数万次/秒的调用。因此相当的不满意。
后来,了解了dubbo和webservice soap之间的在传输和序列化方面的区别(在我看来RPC框架的性能其实最重要的决定性就是这两种)。
dubbo是基于java netty实现二进制数据传输,默认用java Serializer进行序列化的框架,即是属于二进制协议。
soap则是简单对象访问协议 (SOAP:Simple Object Access Protocol)是一种轻量的、简单的、基于 XML 的协议,它被设计成在 WEB 上交换结构化的和固化的信息。
现在原因就在这里了,soap的协议是属于文本协议,而且序列化则是采用xml序列化,soap协议的附加内容太大,导致传输上比dubbo的传输慢,而且序列化xml也比直接二进制序列化慢,所以性能上dubbo都是优于webservice soap的。
尽管,webservice soap的性能低于dubbo,但是考虑到跨语言调用以及实施部署难度,接下来只能继续推行webservice soap。
今天关于基于WebService的性能测试脚本开发和webservice 测试工具的讲解已经结束,谢谢您的阅读,如果想了解更多关于PHP使用SOAP扩展实现WebService的方法 webservice视频教程 c# webservice php webservice、soapUI 做webservice的性能测试、WebService - Axis2基于JAX-WS开发WebService并发布多个WebService、webservice soap简单的性能测试结论的相关知识,请在本站搜索。
本文标签: