2017-06-19 85 views
0

我有一个多线程客户端用于处理并行请求数的WCF。不知怎的,它开始共享两个不同请求/线程的数据;我曾试图改变InstanceContextModeConcurrencyMode如下:WCF并发多线程客户端

  • 默认InstanceContextMode = PerSession ConcurrencyMode =单
  • InstanceContextMode = PerCall ConcurrencyMode =单
  • InstanceContextMode = PerCall ConcurrencyMode =多

但到目前为止没有运气。没有可能导致此并发问题的共享变量和函数。根据MS文档PerCall为每个单个调用创建实例,并且当实例拥有自己的专用内存堆栈时如何共享数据没有任何意义。

工作流程: 有三个主要组件WCF,.Net Assembly 1和.Net Assembly 2.有一个名为WCF的“Process”函数,该函数接受一个字符串参数,并根据通过完成的处理返回结构化对象WCF。 WCF中没有实例变量;功能中的所有内容。该函数对字符串做了很少的处理,并将其转换为结构化对象,然后将其传递给Assembly 1的函数做一些处理,然后使用反射的invoke方法将它传递给Assembly 2的函数。这是以不同方式混合两个不同并发呼叫的最终结果的整个过程。

如果有人能够帮助解决这个问题,我会非常感激。

+0

我们需要看到更多的代码。没有共享变量时如何共享数据? – Laurijssen

+0

在这里发布整个代码是不可能的,但我可以给你一个关于代码工作流程以及它如何工作的想法。 –

回答

0

您是否希望将这些请求并行执行,但不是按顺序执行?在配置文件中添加serviceThrottling我没有问题。我的配置如下所示:

<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> 

正如你所看到的,我可以有最多100个并行请求。我使用默认的InstanceContextModeConcurrencyMode