【问题标题】:wcf webservice timing methods?wcf webservice计时方法?
【发布时间】:2012-09-04 18:58:21
【问题描述】:
【问题讨论】:
标签:
c#
asp.net
wcf
service
profile
【解决方案1】:
这是aspects 的理想场所。查看post sharp。
然后您可以创建一个类似的方面:
/// <summary>
/// Adds execution timing and automatic logging to the tagged method
/// </summary>
[Serializable]
public class MethodTimeAttribute : OnMethodBoundaryAspect
{
private String MethodName { get; set; }
private DateTime StartTime { get; set; }
/// <summary>
/// Method executed at build time. Initializes the aspect instance. After the execution
/// of <see cref="CompileTimeInitialize"/>, the aspect is serialized as a managed
/// resource inside the transformed assembly, and deserialized at runtime.
/// </summary>
/// <param name="method">Method to which the current aspect instance
/// has been applied.</param>
/// <param name="aspectInfo">Unused.</param>
public override void CompileTimeInitialize(MethodBase method, AspectInfo aspectInfo)
{
MethodName = method.DeclaringType.FullName "." method.Name;
}
public override void OnEntry(MethodExecutionArgs args)
{
StartTime = DateTime.Now;
}
public override void OnExit(MethodExecutionArgs args)
{
Log.Debug(this, "Method {0} took {1} to execute", MethodName, DateTime.Now - StartTime);
}
}
你所要做的就是像这样标记你的方法:
[MethodTime]
private void RunFor(TimeSpan runTime){
// do stuff
}
高级后期功能需要许可证,但方法边界方面等简单功能是免费的。
虽然这不会测试您的 wcf 服务的任何网络边界,但它会测试您的服务实施时间。
如果您真的愿意,您可以创建一些自定义行为并将其注入您的 WCF 链以测试时间,但在该阶段出现瓶颈的可能性非常小。更有可能是您发送了大量数据,因此速度很慢,或者您的实现速度很慢,所有这些都可以在服务器端或客户端独立测试。