Async WCF Service and Call Duration Performance Counter

断了今生、忘了曾经 提交于 2019-12-10 10:55:33

问题


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:


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.



来源:https://stackoverflow.com/questions/16824970/async-wcf-service-and-call-duration-performance-counter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!