title: Is it possible to make the WcfTestClient work for custom transport channels?
body: <h2>Goal</h2>
  
  <p>I would like to be able to both host and connect to a vanilla sockets server via WCF, within the hosting framework I am devising.  I want to be able to use WCF to codify the transport and protocol communications that have to be manually managed by sockets programmers today.  This would allow me the ultimate interoperability with Linux server daemons that expose nothing but traditional sockets and proprietary protocols.  I am only interested in verifying that transport channel layer generically using WcfTestClient at this point.  My understanding is that the WcfTestClient does not support complex service methods.</p>
  
  <p><strong>Does anybody think it is possible to make the WcfTestClient work for custom transport channels?</strong>  It would be really sweet to be able to generically use this client to test any number of custom transport channels.  </p>
  
  <h2>Overview</h2>
  
  <p>I am working to understand the WCF Udp sample that is included in the Windows SDK, located typically at C:\Program Files\Microsoft SDKs\Windows\v6.1\Samples\WCFSamples\TechnologySamples\Extensibility\Transport\Udp\CS, assuming that the WCFSamples.zip file is fully extracted from the Samples directory.</p>
  
  <p>These are the steps I have taken thus far:</p>
  
  <ul>
  <li><p>(success): Run the solution's service and client successfully within Visual Studio 2008.</p></li>
  <li><p>(success): connect to a MEX endpoint using the WcfTestClient typically located at C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE</p></li>
  <li><p>(failure): use the WcfTestClient to attempt to execute a method from either the ICalculatorContract or the IDatagramContract service contract.  </p></li>
  </ul>
  
  <p>When I execute the Hello() method, for example, I receive the following error: </p>
  
  <blockquote>
    <p>Friendly message: </p>
    
    <blockquote>
      <p>Failed to invoke the service. Possible
      causes: The service is offline or
      inaccessible; the client-side
      configuration does not match the
      proxy; the existing proxy is invalid.
      Refer to the stack trace for more
      detail. You can try to recover by
      starting a new proxy, restoring to
      default configuration, or refreshing
      the service.</p>
    </blockquote>
    
    <p>Error Details:</p>
    
    <blockquote>
      <p>The CustomBinding on the
      ServiceEndpoint with contract
      'IDatagramContract' lacks a
      TransportBindingElement.  Every
      binding must have at least one binding
      element that derives from
      TransportBindingElement.    at
      System.ServiceModel.Channels.Binding.EnsureInvariants(String
      contractName)    at
      System.ServiceModel.Description.ServiceEndpoint.EnsureInvariants()
      at
      System.ServiceModel.Channels.ServiceChannelFactory.BuildChannelFactory(ServiceEndpoint
      serviceEndpoint)    at
      System.ServiceModel.ChannelFactory.CreateFactory()
      at
      System.ServiceModel.ChannelFactory.OnOpening()
      at
      System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan
      timeout)    at
      System.ServiceModel.ChannelFactory.EnsureOpened()
      at
      System.ServiceModel.ChannelFactory<code>1.CreateChannel(EndpointAddress
      address, Uri via)    at
      System.ServiceModel.ChannelFactory</code>1.CreateChannel()
      at
      System.ServiceModel.ClientBase<code>1.CreateChannel()
      at
      System.ServiceModel.ClientBase</code>1.CreateChannelInternal()
      at
      System.ServiceModel.ClientBase`1.get_Channel()
      at DatagramContractClient.Hello()</p>
    </blockquote>
  </blockquote>
  
  <h2>Understanding the Client Error</h2>
  
  <p>The UdpTransportBindingElement that is defined in the UdpTransport project definitely derives from TransportBindingElement, as shown below, so I'm thinking that there must be something missing from the WcfTestClient configuration file and/or possibly that I have to somehow provide the test client with more information.  I tried basically copying the System.ServiceModel section of the Udp solution's client project into the WcfTestClient's config file, as well as copying the transport assembly dll to the same folder as the test client, but I receive the same error.</p>
  
  <p>My understanding is that the MEX endpoint should be enough to get the information required to invoke simple methods on the service.  Of course, I understand that there is probably more to the story, considering that I'm trying to make a client that was designed to test the out-of-the-box transport channels work with custom transport channels.  </p>
  
  <pre><code>/// &lt;summary&gt;
  /// Udp Binding Element.  
  /// Used to configure and construct Udp ChannelFactories and ChannelListeners.
  /// &lt;/summary&gt;
  public class UdpTransportBindingElement 
      : TransportBindingElement // to signal that we're a transport
      , IPolicyExportExtension // for policy export
      , IWsdlExportExtension
  </code></pre>
  
  <h2>Is ITransportPolicyImport Important for Custom Transport Channels?</h2>
  
  <p>I ask about ITransportPolicyImport because that is an interface that is implemented by the standard WCF derivations of TransportBindingElement, but the Udp sample does not implement this interface, and I cannot find anything useful in web searches or on Safari.  It may not even be relevant.  </p>
  
  <p>For example...</p>
  
  <pre><code>public class HttpTransportBindingElement :
      : TransportBindingElement
      , IWsdlExportExtension
      , IPolicyExportExtension
      , ITransportPolicyImport
  </code></pre>
  
  <h2>Sample Configs...</h2>
  
  <p>The service config looks like this:</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
  
      &lt;!-- 
           add our udpTransport handler for use by binding declarations 
       --&gt;
      &lt;!-- 
           add our standard binding handler for use by binding declarations 
       --&gt;
      &lt;extensions&gt;
        &lt;bindingElementExtensions&gt;
          &lt;add name="udpTransport" type="Microsoft.ServiceModel.Samples.UdpTransportElement, UdpTransport" /&gt;
        &lt;/bindingElementExtensions&gt;
        &lt;bindingExtensions&gt;
          &lt;add name="sampleProfileUdpBinding" type="Microsoft.ServiceModel.Samples.SampleProfileUdpBindingCollectionElement, UdpTransport" /&gt;
        &lt;/bindingExtensions&gt;
      &lt;/extensions&gt;
  
      &lt;services&gt;
        &lt;service name="Microsoft.ServiceModel.Samples.ConfigurableCalculatorService" behaviorConfiguration="udpServiceBehavior"&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost:8000/udpsample"/&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
          &lt;endpoint address="soap.udp://localhost:8001/" 
              binding="sampleProfileUdpBinding" 
              bindingConfiguration="CalculatorServer"
              contract="Microsoft.ServiceModel.Samples.ICalculatorContract" /&gt;
          &lt;endpoint address="soap.udp://localhost:8002/datagram" 
              binding="customBinding" 
              bindingConfiguration="DatagramServer"
              contract="Microsoft.ServiceModel.Samples.IDatagramContract" /&gt;
          &lt;endpoint address="mex"
              binding="mexHttpBinding"
              contract="IMetadataExchange" /&gt;
        &lt;/service&gt;
      &lt;/services&gt;
  
      &lt;bindings&gt;
          &lt;!-- 
           server bindings 
            --&gt;
          &lt;sampleProfileUdpBinding&gt;
              &lt;binding name="CalculatorServer" clientBaseAddress="soap.udp://localhost:8003/" /&gt;
              &lt;binding name="DatagramServer" reliableSessionEnabled="false" /&gt;
          &lt;/sampleProfileUdpBinding&gt;
  
          &lt;customBinding&gt;
          &lt;binding name="DatagramServer"&gt;
              &lt;binaryMessageEncoding /&gt;
              &lt;udpTransport/&gt;
          &lt;/binding&gt;
        &lt;/customBinding&gt;
      &lt;/bindings&gt;
  
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="udpServiceBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="True"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;client&gt;
        &lt;endpoint address="" binding="sampleProfileUdpBinding" bindingConfiguration="CalculatorServer"
          contract="Microsoft.ServiceModel.Samples.ICalculatorContract"
          name="CalculatorClient" /&gt;
      &lt;/client&gt;    
    &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>The client config from the solution looks like this:</p>
  
  <pre><code>  &lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;customBinding&gt;
          &lt;binding name="CustomBinding_IDatagramContract"&gt;
            &lt;binaryMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16"
                maxSessionSize="2048"&gt;
              &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                  maxBytesPerRead="4096" maxNameTableCharCount="16384" /&gt;
            &lt;/binaryMessageEncoding&gt;
            &lt;UpdTransportElementClientSide maxBufferPoolSize="524288" maxMessageSize="65536"
                multicast="false" /&gt;
          &lt;/binding&gt;
        &lt;/customBinding&gt;
        &lt;sampleProfileUdpBinding&gt;
          &lt;binding name="SampleProfileUdpBinding_ICalculatorContract" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              orderedSession="true" reliableSessionEnabled="true" sessionInactivityTimeout="00:10:00" 
              clientBaseAddress="soap.udp://localhost:8003/" /&gt;
        &lt;/sampleProfileUdpBinding&gt;
      &lt;/bindings&gt;
      &lt;client&gt;
        &lt;endpoint address="soap.udp://localhost:8001/" binding="sampleProfileUdpBinding"
            bindingConfiguration="SampleProfileUdpBinding_ICalculatorContract"
            contract="ICalculatorContract" name="SampleProfileUdpBinding_ICalculatorContract" /&gt;
        &lt;endpoint address="soap.udp://localhost:8002/datagram" binding="customBinding"
            bindingConfiguration="CustomBinding_IDatagramContract" contract="IDatagramContract"
            name="CustomBinding_IDatagramContract" /&gt;
      &lt;/client&gt;
      &lt;extensions&gt;
        &lt;bindingElementExtensions&gt;
          &lt;add name="UpdTransportElementClientSide" type="Microsoft.ServiceModel.Samples.UdpTransportElement, UdpTransport" /&gt;
        &lt;/bindingElementExtensions&gt;
        &lt;!-- This was added manually because svcutil.exe does not add this extension to the file --&gt;
        &lt;bindingExtensions&gt;
          &lt;add name="sampleProfileUdpBinding" type="Microsoft.ServiceModel.Samples.SampleProfileUdpBindingCollectionElement, UdpTransport" /&gt;
        &lt;/bindingExtensions&gt;
      &lt;/extensions&gt;
    &lt;/system.serviceModel&gt;
  </code></pre>