http://blog.youkuaiyun.com/chadcao/article/details/28856967
1)JMeter安装
在这里我就不详细叙述了,安装JMeter顺序
1.JDK
2.Tomcat
3.JMeter
2)在VS中创建WCF命名Service1.svc,自动生成接口IService1.cs
IService1.cs代码如下
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.Text;
- namespace HelloWorld
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
- [ServiceContract]
- public interface IService1
- {
- [OperationContract]
- string DoWork(string name);
- [OperationContract]
- bool UserLogin(string username, string password);
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.Serialization;
- using System.ServiceModel;
- using System.Text;
- namespace HelloWorld
- {
- // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
- // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
- public class Service1 : IService1
- {
- public string DoWork(string name)
- {
- return "hello "+name;
- }
- public bool UserLogin(string username, string password)
- {
- using (TestClassesDataContext tcdc = new TestClassesDataContext())
- {
- User item = tcdc.Users.SingleOrDefault(u => u.username.Equals(username) && u.password.Equals(password));
- return item != null ? true : false;
- }
- }
- }
- }
获取Soap/XML-RPC Data
将Service1.svc作为系统启动项在VS中启动(F5)>>双击方法UserLogin>>Formatted
>>在Request中给Name为username,password输入Value,如在这里我输入的是chad,111111
>>单击Invoke,在Response就可以获取你需要的返回值如图
>>单击XML选项卡在Request中获取Soap/XML-RPC Data如下
- <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
- <s:Header>
- <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/UserLogin</Action>
- </s:Header>
- <s:Body>
- <UserLogin xmlns="http://tempuri.org/">
- <username>chad</username>
- <password>111111</password>
- </UserLogin>
- </s:Body>
- </s:Envelope>
3)将WCF发布到IIS
如在这里我发布的URL为http://localhost/Service1.svc
4)在JMeter创建测试计划
启动Tomcat,运行Bin目录下的startup.bat
启动Jmeter,运行Bin目录下的jmeter.bat
创建Thread Group这是用来设置压力测试的并发量(右击Test Plan>>Add>>Threads(Users)>>Thread Group)效果图如下
创建CSV Data Set Config这是用来设置压力测试时需要的数据参数(右击Thread Group>>Add>>Config Element>>CSV Data Set Config)截图如下
创建WebService(SOAP) Request这是用来设置压力测试的对象也就是WCF(右击Thread Group>>Add>>Sampler>>WebService(SOAP) request)截图如下
- <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
- <s:Body>
- <UserLogin xmlns="http://tempuri.org/">
- <username>${username}</username>
- <password>${password}</password>
- </UserLogin>
- </s:Body>
- </s:Envelope>
创建Response Assertion用来设置响应匹配(右击Thread Group>>Add>>Assertions>>Response Assertion)截图如下
创建Summary Report用来查看测试结果(右击Thread Group>>Add>>Listener>>Summary Report)截图如下
创建View Results Tree也是用来查看测试结果(右击Thread Group>>Add>>Listener>>View Results Tree)截图如下
所有所需要的文件创建成功,运行JMeter.结束,谢谢。
-
顶
- 0
-
踩