title: Can you mimic an existing service in WCF?
body: <p>We have a 3rd party vendor service and an in-house service to communicate with it. Everything works perfectly with our in-house service, but I've been asked to write a fall back clone of our vendor's service. The intention is to be able to run up our clone, swap-out the client end-point and allow our in-house service to continue testing against the clone.</p>
  
  <h2>Is it possible to recreate/mimic a service such that an existing client can communicate with it (without modification) as if it were the original service?</h2>
  
  <p>So far I’ve tried 3 things and none of them work.</p>
  
  <h1>1st approach</h1>
  
  <p>Create a simple service, reference the 3rd party service to gain access to the custom types and mimic the <code>[operation Contract]</code>’s.</p>
  
  <p>When I try to communicate with this service  I get the following error.</p>
  
  <p><strong>A first chance exception of type <code>'System.ServiceModel.ActionNotSupportedException'</code> occurred in <code>System.ServiceModel.dll</code>
  Additional information: The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</strong></p>
  
  <p>There is no security requirements as we are using basic http (no ssl). The service model portion of the config file and the service behaviour class attributes are below:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="SimpleBinding" /&gt;
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
        &lt;service behaviorConfiguration="cloneBehavior" name="MyClone"&gt;
          &lt;endpoint address="" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
            contract="MyService.IMyService" /&gt;
          &lt;host&gt;
            &lt;baseAddresses&gt;
              &lt;add baseAddress="http://localhost/clone/" /&gt;
            &lt;/baseAddresses&gt;
          &lt;/host&gt;
        &lt;/service&gt;
      &lt;/services&gt;
      &lt;behaviors&gt;
        &lt;serviceBehaviors&gt;
          &lt;behavior name="cloneBehavior"&gt;
            &lt;serviceMetadata httpGetEnabled="True" httpGetUrl="http://localhost/clone/mex" /&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="False" /&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>and the service behaviour</p>
  
  <pre><code>[ServiceBehavior(Name = "CloneService", 
      ConfigurationName = "MyClone", 
      InstanceContextMode = InstanceContextMode.PerCall, 
      AddressFilterMode = AddressFilterMode.Any)]
  public class MyService : IMyService
  {
  </code></pre>
  
  <p>Everything looks good and I have come to my first dead end.</p>
  
  <h1>2nd approach</h1>
  
  <p>Get rid of my interface/service contract and inherit directly from the interface generated in the reference.cs file.</p>
  
  <p>When I run this service up, I get the following error</p>
  
  <p><b>System.InvalidOperationException: The operations myMethodA and myMethodB have the same action ().  Every operation must have a unique action value.</p>
  
  <p>at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ActionDemuxer.Add(String action, DispatchOperationRuntime operation)
      at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime..ctor(DispatchRuntime dispatch)
      at System.ServiceModel.Dispatcher.DispatchRuntime.GetRuntimeCore()
      at System.ServiceModel.Dispatcher.ChannelDispatcher.OnOpened()
      at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
      at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
      at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
      at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)</b></p>
  
  <p>Taking a look at the generated interface for this method, they are all decorated with the following attribute:</p>
  
  <pre><code>[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
  </code></pre>
  
  <p>My understanding from <a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.operationcontractattribute.action%28v=vs.110%29.aspx" rel="nofollow noreferrer">msdn</a> is that WCF defaults to adding a unique action of the pattern <code>&lt;namespace&gt;/&lt;service&gt;/&lt;operation&gt;[Response]</code>.</p>
  
  <p>If I try setting the action to <code>*</code> then I can hit the service (as expected with the catch all / unmatched message handler), but I can't hit a specific method.</p>
  
  <p>Nevertheless, manually making all the actions unique (and conforming to the above pattern), give this error:</p>
  
  <p><strong>The contract ‘IMyService’ in client configuration does not match the name in service contract, or there is no valid method in this contract.
  …</strong></p>
  
  <p>I have clearly defined methods in the service contract and have come to a second dead end.</p>
  
  <h1>3rd approach</h1>
  
  <p>Using the wsdl.exe tool to generate a service from the wsdl. I followed the instructions from <a href="https://stackoverflow.com/questions/1394930/how-to-generate-web-service-out-of-wsdl">this</a>  SO post to generate an interface and inherit from it.</p>
  
  <p>I’ve also tried generating the service itself by using the <code>clientWsdl.wsdl /l:CS /server</code> command and following the instructions in <a href="http://www.codeproject.com/Articles/12760/Reverse-Engineering-Through-WSDL-EXE" rel="nofollow noreferrer">this</a> post.</p>
  
  <p>After tidying up the generated code and running it up, I’m back to my original error:</p>
  
  <p><strong>A first chance exception of type <code>'System.ServiceModel.ActionNotSupportedException'</code> occurred in System.ServiceModel.dll
  Additional information: The message with Action '' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver.  Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).</strong></p>
  
  <p>At each attempt I have double checked all the config settings and updated the contract at each  stage.</p>
  
  <p>At this stage I'm wondering if it's even possible.</p>