提高 WCF 性能

Increasing WCF Performance

我们设计了 AJAX – 为我们的移动应用程序启用 WCF Web 服务。 Web 服务方法 returns 数据采用 JSON 格式。我们正在观察调用 Web 服务并将其绑定到移动小部件的延迟。数据大小在50K左右。

根据 Code Project ,我们已将更改应用于 WCF Web 服务的 web.config 文件。

同样,在 Whosebug question 之一之后,我们正在尝试增加消息大小。现在,问题是我们应该如何将更改应用到我们当前的 web.config 文件,以便增加消息大小。我们使用默认的 NET 4.0 设置。另外,我们是否需要在客户端 web.config 文件中定义终点。有人可以提供客户端 web.config 吗?

我们当前的服务器 web.config 设置是:

<?xml version="1.0" encoding="utf-8"?>

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<identity impersonate="false" />
<webServices>
  <protocols>
    <add name="HttpGet"/>
    <add name="HttpPost"/>
  </protocols>
</webServices>
</system.web>

<system.serviceModel>
<diagnostics performanceCounters="All"></diagnostics>
<behaviors>

  <serviceBehaviors>
    <behavior name="ServiceBehavior">

      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />

      <!--Increase WCF Performance-->
      <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>      

    </behavior>
  </serviceBehaviors>

  <endpointBehaviors>
    <behavior name="MobileService.webHttpBehavior">
      <enableWebScript />          
    </behavior>        
  </endpointBehaviors>
</behaviors>

<!--Increase WCF Performance-->
<bindings>
  <basicHttpBinding>
    <binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>              
    </binding>        
  </basicHttpBinding>
</bindings>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

<services>
  <service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" />        
  </service>
</services>

</system.serviceModel>

</configuration>

任何人都可以确认我应用的更改是否有效并将其标记为确认答案吗?

 <system.serviceModel>
 <diagnostics performanceCounters="All"></diagnostics>
 <behaviors>

  <endpointBehaviors>
    <behavior name="MobileService.webHttpBehavior">
      <enableWebScript />
    </behavior>
  </endpointBehaviors>

  <serviceBehaviors>
    <behavior name="ServiceBehavior">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />

      <!--Increase WCF Performance-->
      <serviceThrottling maxConcurrentCalls="100" maxConcurrentInstances="100" maxConcurrentSessions="100"/>      

    </behavior>
</serviceBehaviors>     
</behaviors>

<!--Increase WCF Performance-->
<bindings>
  <webHttpBinding>
    <binding name="webHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
      <readerQuotas maxDepth="32" maxArrayLength="20000000" maxStringContentLength="20000000"/>
    </binding>
  </webHttpBinding> 
</bindings>

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

<services>
  <service name="MobileWCFService.Service1" behaviorConfiguration="ServiceBehavior">
    <endpoint address="" binding="webHttpBinding" contract="MobileWCFService.Service1" behaviorConfiguration="MobileService.webHttpBehavior" bindingConfiguration="webHttp" />        
  </service>
</services>