异步WCF服务和通话时间性能计数器 [英] Async WCF Service and Call Duration Performance Counter
问题描述
我试图来衡量的通话时长性能WCF服务方法计数器。
I am trying to measure the Calls Duration performance counter for a WCF service method.
我有一个非常简单的WCF服务为如下。
I have a very simple WCF service as given below.
Service接口:
Service interface:
[ServiceContract]
public interface IFooService
{
[OperationContract]
string DoSomeExpensiveOperation();
}
服务实现:
public class FooService : IFooService
{
public string DoSomeExpensiveOperation()
{
Thread.Sleep(3000);
return "Some valuable information";
}
}
在执行同步(如上述),我可以看到正在填充通话时间。
When the implementation is synchronous (as given above), I can see the Calls Duration being populated.
然而,当服务实现是异步(如下面给出的),没有被填充。
However, when the service implementation is async (as given below), nothing is populated.
Service接口:
Service interface:
[ServiceContract]
public interface IFooService
{
[OperationContract]
Task<string> DoSomeExpensiveOperation();
}
服务实现:
public class FooService : IFooService
{
public async Task<string> DoSomeExpensiveOperation()
{
Thread.Sleep(3000);
return await Task.FromResult("Some expensive value");
}
}
我甚至试过发布的await后自定义性能计数器。即使这样没有工作。
I've even tried publishing a custom performance counter after the await. Even this did not work.
鸭preciate如果任何人都可以阐明这一些轻。
Appreciate if anyone can shed some light on this.
谢谢!
推荐答案
通话时间不支持异步调用(操作/服务或端点)。
其他WCF柜台仍然是有效的,但不是这一个。
Call Duration is not supported for async calls (Operation/Service or Endpoint). Others WCF counters are still valid but not this one.
MSDN ,
在上一个异步WCF服务的通话时间计数器使用
总是返回-1。
When used on an asynchronous WCF service the Call Duration counter will always return -1.
这篇关于异步WCF服务和通话时间性能计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!