如何使WCF服务并发工作?

时间:2018-12-12 13:44:42

标签: c# http wcf web concurrency

我是wcf的新手,我并发10个请求来测试我的wcf服务,但只是随机响应,3、7、1,有时甚至没有响应。我进行了很多搜索,并在web.config中填充了一些代码,设置了currencymod,instancemode,但结果仍然没有任何变化。 希望有人可以帮助检查我的代码。

wcf服务web.config中的相关代码

<system.web>
<compilation debug="true" targetFramework="4.0" />
<httpRuntime />
<pages controlRenderingCompatibilityVersion="4.0" /></system.web>
<endpoint address="" binding="basicHttpBinding" contract="ADGrainWcfService.ISQLiteHelperService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

  <behaviors>
  <serviceBehaviors>
    <behavior>

      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />

      <serviceDebug includeExceptionDetailInFaults="true" />
    <dataContractSerializer maxItemsInObjectGraph="2147483647"/>
      <serviceThrottling maxConcurrentCalls="200" maxConcurrentSessions="5000" maxConcurrentInstances="200" />
    </behavior>
  </serviceBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
        <basicHttpBinding>      
<bindingname="basicHttpBinding"closeTimeout="00:30:00"openTimeout="00:30:00" receiveTimeout="00:30:00" sendTimeout="00:30:00"transferMode="Buffered"hostNameComparisonMode="StrongWildcard"
 maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
 maxReceivedMessageSize="2147483647">
  </binding>

 </basicHttpBinding>
</bindings>

<system.net>
 <connectionManagement>
  <add address="*" maxconnection="200"/>
 </connectionManagement>
</system.net>

服务代码:

[ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall,ConcurrencyMode =ConcurrencyMode.Multiple)]
  public class WithDrawService : IWithDrawService
  {

       int IWithDrawService.TestConcurrent()
       {
          return 1;
       }
  }

此服务已部署在具有2048MB内存的Windows Server 2008 r2上

我发现“设置ServicePointManager.DefaultConnectionLimit”可以解决我的问题,但是我不知道应该在哪里设置它。我试图在我的服务类构造函数和客户端中设置它,但是没有效果。

0 个答案:

没有答案