简体   繁体   English

WCF并发和多线程客户端

[英]WCF Concurrency & Multi Threaded Client

I have a WCF that is used by a multi threaded client for processing the number of requests parallel. 我有一个WCF,多线程客户端使用它来处理并行请求数。 Somehow it starts sharing data of two different requests/threads; 它以某种方式开始共享两个不同请求/线程的数据; I have tried to change the InstanceContextMode and ConcurrencyMode as following: 我试图按以下方式更改InstanceContextModeConcurrencyMode

  • Default InstanceContextMode = PerSession ConcurrencyMode = Single 默认InstanceContextMode = PerSession ConcurrencyMode =单个
  • InstanceContextMode = PerCall ConcurrencyMode = Single InstanceContextMode = PerCall ConcurrencyMode =单
  • InstanceContextMode = PerCall ConcurrencyMode = Multiple InstanceContextMode = PerCall ConcurrencyMode =多个

But there is no luck so far. 但是到目前为止没有运气。 There is no shared variables and functions which may cause of this concurrency issue. 没有可能导致此并发问题的共享变量和函数。 According to the MS documentation PerCall creates instance for each single call and it doesn't make any sense that how data is shared between instances when they have their own private memory stack. 根据MS文档, PerCall为每个单个调用创建实例,并且当实例拥有自己的私有内存堆栈时,如何在实例之间共享数据毫无意义。

Workflow: There are three main components WCF, .Net Assembly 1 and .Net Assembly 2. There is a function named "Process" of WCF which takes a string parameter and returns the structured object based on the processing done through WCF. 工作流程:WCF包含三个主要组件:.Net程序集1和.Net程序集2。WCF的一个名为“ Process”的函数采用字符串参数,并根据通过WCF完成的处理返回结构化对象。 There is no instance variable in the WCF; WCF中没有实例变量。 everything in the function. 功能中的所有内容。 This function does little processing on the string and convert it into the structured object then pass it to the function of Assembly 1 does some processing and then pass it to the function of Assembly 2 using the invoke method of reflection. 此函数对字符串进行很少的处理,然后将其转换为结构化对象,然后将其传递给Assembly 1的函数,然后进行一些处理,然后使用反射的invoke方法将其传递给Assembly 2的函数。 This is the entire process which somehow mix the end result of two different concurrent calls. 这是整个过程,以某种方式将两个不同的并发调用的最终结果混合在一起。

I would be really thankful if anyone can help to figure this issue out. 如果有人可以帮助解决这个问题,我将非常感谢。

Do you want to have those requests to be performed in parallel, but not sequentially as you have them? 您是否希望并行执行这些请求,而不是像处理请求那样依次执行? I have no issues with that by adding serviceThrottling in config file. 通过在配置文件中添加serviceThrottling ,我对此没有任何问题。 My config looks like this: 我的配置如下所示:

<system.serviceModel>
    <services>
      <service name="TeleEcgService.Service">
        <endpoint address="" binding="basicHttpBinding" contract="TeleEcgService.IService"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceThrottling maxConcurrentCalls="100" maxConcurrentSessions="1" maxConcurrentInstances="100"/>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https"/>
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <bindings>
      <basicHttpBinding>
        <binding maxReceivedMessageSize="50000000">
          <!--
          <security mode="Transport">
          </security>
          -->
        </binding>
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>

As you can see, I can have max 100 parallel requests. 如您所见,我最多可以有100个并行请求。 And I use default InstanceContextMode and ConcurrencyMode 我使用默认的InstanceContextModeConcurrencyMode

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM