title: Why do I get ActionNotSupportedException for my WCF client/service?
body: <p>I'm learning WCF, specifically I'm learning how to write them contract first, ala <a href="http://wscfblue.codeplex.com/" rel="noreferrer">wscf.blue</a></p>
  
  <p>I can create a WCF client/service the contract last way (Microsoft)
  I can create a WCF client/service the contract first way (WSCF)</p>
  
  <p>But, if I create a contract first service, then try to add it the Microsoft way (Service Reference) instead of the WSCF.blue way (share contract and generate client) it doesn't work.</p>
  
  <p>It throws an <code>ActionNotSupportedException</code> with the message <code>The message with Action 'urn:test-com:simple:testMethodIn' 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).</code></p>
  
  <p>And I have no idea what that means.</p>
  
  <p>Here is my test contract:</p>
  
  <p>SimpleModel.xsd</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema xmlns="urn:test-com:simple" xmlns:mstns="urn:test-com:simple" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:test-com:simple" elementFormDefault="qualified" attributeFormDefault="unqualified" id="SimpleModel"&gt;
      &lt;xs:complexType name="PayloadType"&gt;
          &lt;xs:sequence&gt;
              &lt;xs:element name="AString" type="xs:string" nillable="1" minOccurs="0"/&gt;
              &lt;xs:element name="AnInt" type="xs:int"/&gt;
          &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>SimpleMessages.xsd</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema xmlns="urn:test-com:simple" xmlns:mstns="urn:test-com:simple" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:smod="http://tempuri.org/SimpleModel.xsd" targetNamespace="urn:test-com:simple" elementFormDefault="qualified" attributeFormDefault="unqualified" id="SimpleMessages"&gt;
      &lt;xs:include schemaLocation="SimpleModel.xsd"/&gt;
      &lt;xs:element name="TestMethod"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="APayload" type="PayloadType" minOccurs="0"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
      &lt;xs:element name="TestMethodResponse"&gt;
          &lt;xs:complexType&gt;
              &lt;xs:sequence&gt;
                  &lt;xs:element name="Output" type="PayloadType"/&gt;
              &lt;/xs:sequence&gt;
          &lt;/xs:complexType&gt;
      &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Simple.wsdl</p>
  
  <pre><code>&lt;!--WSDL generated by thinktecture WSCF; version 1.0.13.0--&gt;
  &lt;!--Tuesday, 09-10-2012 - 02:41 PM--&gt;
  &lt;definitions xmlns:tns="urn:test-com:simple" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" name="Simple" targetNamespace="urn:test-com:simple"&gt;
      &lt;wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/&gt;
      &lt;types&gt;
          &lt;xsd:schema&gt;
              &lt;xsd:import schemaLocation="SimpleMessages.xsd" namespace="urn:test-com:simple"/&gt;
          &lt;/xsd:schema&gt;
      &lt;/types&gt;
      &lt;message name="testMethodIn"&gt;
          &lt;wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/&gt;
          &lt;part name="parameters" element="tns:TestMethod"/&gt;
      &lt;/message&gt;
      &lt;message name="testMethodOut"&gt;
          &lt;wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/&gt;
          &lt;part name="parameters" element="tns:TestMethodResponse"/&gt;
      &lt;/message&gt;
      &lt;portType name="SimpleInterface"&gt;
          &lt;wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/&gt;
          &lt;operation name="TestMethod"&gt;
              &lt;wsdl:documentation xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"/&gt;
              &lt;input message="tns:testMethodIn"/&gt;
              &lt;output message="tns:testMethodOut"/&gt;
          &lt;/operation&gt;
      &lt;/portType&gt;
      &lt;binding name="BasicHttpBinding_SimpleInterface" type="tns:SimpleInterface"&gt;
          &lt;soap:binding transport="http://schemas.xmlsoap.org/soap/http"/&gt;
          &lt;operation name="TestMethod"&gt;
              &lt;soap:operation soapAction="urn:test-com:simple:testMethodIn" style="document"/&gt;
              &lt;input&gt;
                  &lt;soap:body use="literal"/&gt;
              &lt;/input&gt;
              &lt;output&gt;
                  &lt;soap:body use="literal"/&gt;
              &lt;/output&gt;
          &lt;/operation&gt;
      &lt;/binding&gt;
      &lt;service name="ISimple"&gt;
          &lt;port name="NewPort" binding="tns:BasicHttpBinding_SimpleInterface"&gt;
              &lt;soap:address location="http://localhost:50862/Simple.svc"/&gt;
          &lt;/port&gt;
      &lt;/service&gt;
  &lt;/definitions&gt;
  </code></pre>
  
  <p>Here's the system.serviceModel section from web.config</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;behaviors&gt;
          &lt;serviceBehaviors&gt;
              &lt;behavior name="SimpleServiceBehaviour"&gt;
                  &lt;serviceMetadata externalMetadataLocation="http://localhost:50862/TestContract/Simple.wsdl" httpGetEnabled="true"/&gt;
              &lt;/behavior&gt;
          &lt;/serviceBehaviors&gt;
      &lt;/behaviors&gt;
      &lt;diagnostics&gt;
          &lt;messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true"/&gt;
      &lt;/diagnostics&gt;
      &lt;bindings&gt;
          &lt;basicHttpBinding&gt;
              &lt;binding name="BasicHttpBinding_SimpleInterface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"&gt;
                  &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/&gt;
                  &lt;security mode="None"&gt;
                      &lt;transport clientCredentialType="None" proxyCredentialType="None" realm=""/&gt;
                      &lt;message clientCredentialType="UserName" algorithmSuite="Default"/&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
      &lt;services&gt;
          &lt;service behaviorConfiguration="SimpleServiceBehaviour" name="SimpleContract.Simple"&gt;
              &lt;endpoint address="http://localhost:50862/Simple.svc" behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SimpleInterface" contract="ISimple"/&gt;
          &lt;/service&gt;
      &lt;/services&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>If I add a service reference to <code>http://localhost:50862/Simple.svc</code> Every appears to generate OK.</p>
  
  <p>I create this in the client app.config using the service config editor by importing the web.config:</p>
  
  <pre><code>&lt;system.serviceModel&gt;
      &lt;client&gt;
          &lt;endpoint address="http://localhost:50862/Simple.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_SimpleInterface" contract="SI.SimpleInterface" name="NewPort"/&gt;
      &lt;/client&gt;
      &lt;bindings&gt;
          &lt;basicHttpBinding&gt;
              &lt;binding name="BasicHttpBinding_SimpleInterface" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true"&gt;
                  &lt;readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/&gt;
                  &lt;security mode="None"&gt;
                      &lt;transport clientCredentialType="None" proxyCredentialType="None" realm=""/&gt;
                      &lt;message clientCredentialType="UserName" algorithmSuite="Default"/&gt;
                  &lt;/security&gt;
              &lt;/binding&gt;
          &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  &lt;/system.serviceModel&gt;
  </code></pre>
  
  <p>And if I run my test code:</p>
  
  <pre><code>static void Main(string[] args)
  {
      SimpleInterfaceClient client = new SimpleInterfaceClient();
  
      var ret = client.TestMethod(new PayloadType() { AnInt = 7, AString = "bob" });
  
      Console.WriteLine(ret.ToString());
      Console.ReadLine();
  }
  </code></pre>
  
  <p>Inside the TestMethod proxy the following line:</p>
  
  <pre><code>return base.Channel.TestMethod(request);
  </code></pre>
  
  <p>Throws the following exception</p>
  
  <pre><code>System.ServiceModel.ActionNotSupportedException occurred
    Message="The message with Action 'urn:test-com:simple:testMethodIn' 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)."
    Source="System.ServiceModel"
    StackTrace:
         at System.ServiceModel.Channels.ServiceChannel.ThrowIfFaultUnderstood(Message reply, MessageFault fault, String action, MessageVersion version, FaultConverter faultConverter)
  </code></pre>
  
  <p>Can anybody help?</p>
  
  <p>Thanks,</p>
  
  <p>J.</p>
  
  <p><strong>First Edit</strong></p>
  
  <p>OK, I've now found that there is something going wrong with my doc-lit-wrapped wsdl and the code generators. wscf.blue does not like it's messages to have nullable types marked as nillable. It falls out of wrapped mode and the method implementations are not unwrapped.</p>
  
  <p>But, if I don't mark them as nillable, the client code falls out of wrapping mode because they are nullable types not marked as nillable.</p>
  
  <p>With nullable types marked not nillable:</p>
  
  <p>Server side:</p>
  
  <pre><code>[System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple/ISimple/TestMethod", ReplyAction="urn:test-com:simple/ISimple/TestMethodResponse")]
  [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
  [return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
  PayloadType TestMethod(PayloadType APayload);
  </code></pre>
  
  <p>Client Side:</p>
  
  <pre><code>// CODEGEN: Generating message contract since element name APayload from namespace urn:test-com:simple is not marked nillable
  [System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple:testMethodIn", ReplyAction="*")]
  DesktopClientTest_ServiceReference.SI.TestMethodResponse TestMethod(DesktopClientTest_ServiceReference.SI.TestMethodRequest request);
  </code></pre>
  
  <p>With nullable types marked as nillable:</p>
  
  <p>Server side:</p>
  
  <pre><code>// CODEGEN: Parameter 'Output' requires additional schema information that cannot be captured using the parameter mode. The specific attribute is 'System.Xml.Serialization.XmlElementAttribute'.
  [System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple/ISimple/TestMethod", ReplyAction="urn:test-com:simple/ISimple/TestMethodResponse")]
  [System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
  [return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
  TestMethodResponse TestMethod(TestMethodRequest request);
  </code></pre>
  
  <p>Client side:</p>
  
  <pre><code>[System.ServiceModel.OperationContractAttribute(Action="urn:test-com:simple:testMethodIn", ReplyAction="*")]
  [return: System.ServiceModel.MessageParameterAttribute(Name="Output")]
  DesktopClientTest_ServiceReference.SI.PayloadType TestMethod(DesktopClientTest_ServiceReference.SI.PayloadType APayload);
  </code></pre>
  
  <p>However I have no idea whether that's the cause, let alone how to fix it.
  That said, I <strong>do</strong> know that nullable types should be marked nillable for doc-lit-wrapped wsdl.</p>