WCF启动花费了太多时间

时间:2011-06-16 10:50:08

标签: wcf c#-4.0

在所有呼叫执行非常快之后,WCF服务在第一次请求时大约需要5-6秒。 下面是我的WCF服务的客户端配置。

使用IIS托管。

        WSHttpBinding binding = new WSHttpBinding();
        binding.SendTimeout = TimeSpan.FromMinutes(1);
        binding.OpenTimeout = TimeSpan.FromMinutes(1);
        binding.CloseTimeout = TimeSpan.FromMinutes(1);
        binding.ReceiveTimeout = TimeSpan.FromMinutes(1);
        binding.AllowCookies = false;
        binding.BypassProxyOnLocal = false;
        binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;

        binding.MessageEncoding = WSMessageEncoding.Mtom; 

        binding.TextEncoding = System.Text.Encoding.UTF8;
        binding.UseDefaultWebProxy = true;
        binding.Name = "BasicHttpBinding_ILearningService";


        binding.Security.Mode = SecurityMode.Transport;              
        binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
        binding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
        binding.Security.Transport.Realm = "";

服务器端配置

<services>
  <service behaviorConfiguration="LearningServiceServiceBehavior" name="LearningService">
    <host>

      <baseAddresses>
        <add baseAddress="https://xxxxx/LearningService.svc" />
      </baseAddresses>
    </host>
    <endpoint address="" binding="wsHttpBinding" bindingConfiguration="TransportSecurity" contract="ILearningSuiteService">
      <identity>
        <dns value="localhost" />
      </identity>
     </endpoint>

    <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="TransportSecurity" messageEncoding="Mtom" sendTimeout="00:1:00" openTimeout="00:2:00">
      <security mode="Transport">
        <transport clientCredentialType="None" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="LearningServiceServiceBehavior">
      <serviceMetadata httpsGetEnabled="true" httpGetEnabled="false" httpGetUrl="http://xxxxxxx/Metadata" httpsGetUrl="https://xxxxxxxx/Metadata" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
</behaviors>

3 个答案:

答案 0 :(得分:4)

您可能会看到的另一个问题是,当您使用传输安全性时,每次创建新代理时都会在客户端上进行证书验证。例如,由于证书的撤销列表没有及时提供,证书验证是否可能很昂贵?

尝试关闭安全性,看看是否会改变行为

答案 1 :(得分:2)

虽然不完全明确,但看起来你是IIS托管(我说不明确因为你在IIS托管中没有指定baseAddresses,而是实际的.svc文件是服务的基地址)

假设您是IIS主机,您是否看到了工作进程的启动时间?根据您使用的Windows版本,您可以使用Windows Server AppFabric在第一次请求之前自动启动服务

答案 2 :(得分:1)

第一次拨打电话时,客户端会建立与服务器的连接,服务器会进行必要的身份验证,这可能需要一些时间。 根据我在项目中发现的内容,如果您的合同很大,WCF序列化可能会在第一时间花费很多时间。之后,序列化可以更快。