Async WCF Service and Call Duration Performance Co

2019-05-26 03:09发布

I am trying to measure the Calls Duration performance counter for a WCF service method.

I have a very simple WCF service as given below.

Service interface:

[ServiceContract]
public interface IFooService
{      
    [OperationContract]
    string DoSomeExpensiveOperation();
}

The service implementation:

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 interface:

[ServiceContract]
public interface IFooService
{       
    [OperationContract]
    Task<string> DoSomeExpensiveOperation();

}

The service implementation:

public class FooService : IFooService
{        
    public async Task<string> DoSomeExpensiveOperation()
    {
        Thread.Sleep(3000);
        return await Task.FromResult("Some expensive value");
    }
}

I've even tried publishing a custom performance counter after the await. Even this did not work.

Appreciate if anyone can shed some light on this.

Thanks!

1条回答
甜甜的少女心
2楼-- · 2019-05-26 03:31

Call Duration is not supported for async calls (Operation/Service or Endpoint). Others WCF counters are still valid but not this one.

From MSDN,

When used on an asynchronous WCF service the Call Duration counter will always return -1.

查看更多
登录 后发表回答