title: WCF ChannelFactory IDuplexSessionChannel
body: <p>I am using a <code>ChannelFactory</code> to communicate with external services by sending raw soap requests. I have a NetTcp endpoint that uses the <code>IDuplexSessionChannel</code>. I tried creating a <code>IRequestChannel/IRequestSessionChannel</code> using <code>binding.BuildChannelFactory&lt;T&gt;()</code>, but that did not work (threw exception). From what I read online, duplex channels can be used like request channels, where you call a service method and get an immediate response. I want to know if the below code accomplishes that. I searched everywhere to see an example of <code>ChannelFactory</code> and <code>IDuplexSessionChannel</code>, but could not find anything. Lastly, if this were an IDuplexChannel instead of an IDuplexSessionChannel, would the implementation be any different since one is sessionful and the other isn't?</p>
  
  <pre><code>IChannelFactory factory;
  IChannel        channel;
  
  Binding         binding = GetBindingFromConfig( bindingName );
  EndpointAddress address = new EndpointAddress( endpointAddress );
  
  if( binding.CanBuildChannelFactory&lt;IDuplexSessionChannel&gt;() )
  {
      factory = binding.BuildChannelFactory&lt;IDuplexSessionChannel&gt;();
      factory.Open();
      channel = ( (IChannelFactory&lt;IDuplexSessionChannel&gt;)factory ).CreateChannel( address );
      channel.Open();
  
      ( (IDuplexSessionChannel)channel ).Send( requestMessage );
      ( (IDuplexSessionChannel)channel ).TryReceive( Timespan.MaxValue, out responseMessage );
  }
  </code></pre>
  
  <p>Here is my configuration file:</p>
  
  <pre><code>&lt;netTcpBinding&gt;
      &lt;binding
          name="xyz"
          closeTimeout="00:01:00"
          openTimeout="00:01:00"
          receiveTimeout="00:10:00"
          sendTimeout="00:01:00"
          transactionFlow="false"
          transferMode="Buffered"
          transactionProtocol="OleTransactions"
          hostNameComparisonMode="StrongWildcard"
          listenBacklog="10"
          maxBufferPoolSize="524288"
          maxBufferSize="10485760"
          maxConnections="10"
          maxReceivedMessageSize="10485760"&gt;
  
          &lt;readerQuotas
              maxDepth="32"
              maxStringContentLength="8192"
              maxArrayLength="10485760"
              maxBytesPerRead="4096"
              maxNameTableCharCount="16384" /&gt;
  
          &lt;reliableSession
              ordered="true"
              inactivityTimeout="00:10:00"
              enabled="false" /&gt;
  
          &lt;security mode="Transport" /&gt;
      &lt;/binding&gt;
  &lt;/netTcpBinding&gt;
  </code></pre>