0
votes

I have a WCF that is used by a multi threaded client for processing the number of requests parallel. Somehow it starts sharing data of two different requests/threads; I have tried to change the InstanceContextMode and ConcurrencyMode as following:

  • Default InstanceContextMode = PerSession ConcurrencyMode = Single
  • InstanceContextMode = PerCall ConcurrencyMode = Single
  • InstanceContextMode = PerCall ConcurrencyMode = Multiple

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.

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. There is no instance variable in the 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. 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.

1
we need to see more code. How can data be shared when there are no shared variables?Serve Laurijssen
Publishing the entire code here is not possible but I can give you an idea about the workflow of the code and how it works.Shahid Iqbal

1 Answers

0
votes

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. 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. And I use default InstanceContextMode and ConcurrencyMode