JMeter实现对WCF性能测试

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);
    }
}
Service1.svc代码如下

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值