JMeter实现对WCF性能测试

http://blog.csdn.net/chadcao/article/details/28856967

1)JMeter安装

在这里我就不详细叙述了,安装JMeter顺序

1.JDK

2.Tomcat

3.JMeter

2)在VS中创建WCF命名Service1.svc,自动生成接口IService1.cs

IService1.cs代码如下

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Runtime.Serialization;  
  5. using System.ServiceModel;  
  6. using System.Text;  
  7.   
  8. namespace HelloWorld  
  9. {  
  10.     // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.  
  11.     [ServiceContract]  
  12.     public interface IService1  
  13.     {  
  14.         [OperationContract]  
  15.         string DoWork(string name);  
  16.         [OperationContract]  
  17.         bool UserLogin(string username, string password);  
  18.     }  
  19. }  
Service1.svc代码如下

[csharp]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Runtime.Serialization;  
  5. using System.ServiceModel;  
  6. using System.Text;  
  7.   
  8. namespace HelloWorld  
  9. {  
  10.     // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.  
  11.     // 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.  
  12.     public class Service1 : IService1  
  13.     {  
  14.         public string DoWork(string name)  
  15.         {  
  16.             return "hello "+name;  
  17.         }  
  18.         public bool UserLogin(string username, string password)  
  19.         {  
  20.             using (TestClassesDataContext tcdc = new TestClassesDataContext())  
  21.             {  
  22.                 User item = tcdc.Users.SingleOrDefault(u => u.username.Equals(username) && u.password.Equals(password));  
  23.                 return item != null ? true : false;  
  24.             }  
  25.         }  
  26.     }  
  27. }  

获取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如下

[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  
  2.   <s:Header>  
  3.     <Action s:mustUnderstand="1" xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none">http://tempuri.org/IService1/UserLogin</Action>  
  4.   </s:Header>  
  5.   <s:Body>  
  6.     <UserLogin xmlns="http://tempuri.org/">  
  7.       <username>chad</username>  
  8.       <password>111111</password>  
  9.     </UserLogin>  
  10.   </s:Body>  
  11. </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)截图如下


[html]  view plain  copy
  在CODE上查看代码片 派生到我的代码片
  1. <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">  
  2.   <s:Body>  
  3.     <UserLogin xmlns="http://tempuri.org/">  
  4.       <username>${username}</username>  
  5.       <password>${password}</password>  
  6.     </UserLogin>  
  7.   </s:Body>  
  8. </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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值