简单的WCF调用需要花费很多时间

Lou*_*hys 8 .net debugging wcf soap wshttpbinding

我正在创建一个WCF服务器 - 客户端应用程序.但是,在我的第一次测试中,一个简单的调用(该方法基本上只return true;需要)需要很多时间(~5秒)

我试图追踪它,这是一个呼叫追踪的截图 在此输入图像描述

你可以看到第2行和第3行之间的时间是5秒(虽然老实说我不知道​​第2行和第3行是什么意思)

在客户端(调用者)配置中,绑定是这样的(主要由Visual Studio生成)

    <wsHttpBinding>
        <binding name="WSHttpBinding_IAgent" closeTimeout="00:01:00"
          openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
          bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
          maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
          textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
          <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
            maxBytesPerRead="4096" maxNameTableCharCount="16384" />
          <reliableSession ordered="true" inactivityTimeout="00:10:00"
            enabled="false" />
          <security mode="None">
          </security>
        </binding>
      </wsHttpBinding>
Run Code Online (Sandbox Code Playgroud)

并在服务器上

<wsHttpBinding>
    <binding name="WSHttpBinding_IAgent" closeTimeout="00:01:00"
      openTimeout="00:01:00" receiveTimeout="00:05:00" sendTimeout="00:05:00"
      bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
      maxBufferPoolSize="16777216" maxReceivedMessageSize="16777216"
      messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
      allowCookies="false">
      <readerQuotas maxDepth="32" maxStringContentLength="16777216"
        maxArrayLength="16384" maxBytesPerRead="16384" maxNameTableCharCount="16384" />
      <reliableSession ordered="true" inactivityTimeout="00:10:00"
        enabled="false" />
      <security mode="None"/>
    </binding>
Run Code Online (Sandbox Code Playgroud)

我称之为这样的方式

var client = new AgentClient(binding, BuildEndpointAddress(hostName, port));
for(int i =0; i<10; i++)
    client.IsAlive(); //this call is very slow despite just returning true;
    // subsequent calls are also slow so probably not because of wake-up time
Run Code Online (Sandbox Code Playgroud)

注意,对于此测试,服务器和客户端都在同一台计算机上,因此它不会成为网络问题.知道是什么原因造成的缓慢或如何找到更多信息来解决这个问题?

Mar*_*man 0

要查找更多信息,您可能需要将 Windows 事件跟踪 (ETW) 与BCL 团队的 codeplex 站点中的Perfmonitor工具结合使用。该工具的众多功能之一是它可以每毫秒对指令指针进行采样,并为您提供每个采样的托管调用堆栈。这可以让您了解代码在这些时间内正在做什么。

附:这是使用此工具的文章的另一个链接: http://naveensrinivasan.com/category/net/etw-net/