title: c# wcf - exception thrown when calling open() on proxy class
body: <p>I have the following problem, basically i have a WCF service which operates fine in small tests. However when i attempt a batch/load test i get an <code>InvalidOperationException</code> with the message when the open() method is called on the proxy class:</p>
  
  <blockquote>
    <p><em>"The communication object, System.ServiceModel.Channels.ServiceChannel, cannot be modified while it is in the Opened state."</em></p>
  </blockquote>
  
  <p>I have searched google, but cannot find anyone else really quoting this exception message.</p>
  
  <p>I guess some further info on the service may be necessary for a diagnosis - when the service receives data through one of it's exposed methods, it basically performs some processing and routes the data to a service associated with the data (different data will result in different routing). To ensure that the service runs as quickly as possible, each cycle of receiving, processing and routing of the data is handled by a seperate thread in the threadpool. could this be a problem arising from one thread calling <code>proxyClass.Open()</code> whilst another is already using it? would a <code>lock</code> block eliminate this problem, if indeed this is the problem?</p>
  
  <p>thanks guys,  - ive been workikng on this project for <strong>too</strong> long, and finally want to see the back of it - but this appears to be the last stumbling block, so any help much appreciated :-)</p>
  
  <p>=========================================================================
  <br /><br />
  thanks for highlighting that i shouldn't be using the <code>using</code> construct for WCF proxy classes. However the MSDN article isn't the most clearly written piece of literature ever, so one quick question: should i be using a proxy as such:</p>
  
  <pre><code>try
  {
      client = new proxy.DataConnectorServiceClient();
      client.Open();
      //do work
      client.Close();
   }
   .................. //catch more specific exceptions
   catch(Exception e)
   {
      client.Abort();
   }
  </code></pre>