title: WCF CustomBinding - Cannot obtain Metadata with custom authorization policy
body: <p>After solving my previous problem, I wanted to convert the netTcpBinding to a customBinding, which I managed succesfully. However, WcfTestClient (and normal client) give an error while trying to extract metadata when I put a custom authorization policy in place (it works fine without!).</p>
  
  <p>My config:</p>
  
  <pre><code>&lt;serviceAuthorization principalPermissionMode="Custom"&gt;
          &lt;authorizationPolicies&gt;
            &lt;add policyType="Sample.Tools.CustomAuthorizationPolicy, Sample" /&gt;
          &lt;/authorizationPolicies&gt;
  </code></pre>
  
  <p>I've read on MSDN (here: <a href="http://social.msdn.microsoft.com/Forums/en-IE/wcf/thread/80a33bc6-0765-45f6-8af5-0a414a5cc40d" rel="nofollow">http://social.msdn.microsoft.com/Forums/en-IE/wcf/thread/80a33bc6-0765-45f6-8af5-0a414a5cc40d</a>) that this may be caused because a custom authorization manager is also required. I tried this and added the CustomAuthorizationManager as well (with CheckAccessCore always returning true), but it didn't work.</p>
  
  <p>This is added in the config as:</p>
  
  <pre><code>    &lt;serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="Sample.Tools.CustomAuthorizationManager, Sample"&gt;
          &lt;authorizationPolicies&gt;
            &lt;add policyType="Sample.Tools.CustomAuthorizationPolicy, Sample" /&gt;
          &lt;/authorizationPolicies&gt;
  </code></pre>
  
  <p>The rest of the config:</p>
  
  <p>Binding:</p>
  
  <pre><code>&lt;customBinding&gt;
        &lt;binding name="SampleBinding" receiveTimeout="00:05:00"&gt;
          &lt;transactionFlow/&gt;
          &lt;security authenticationMode="SecureConversation" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"&gt;
              &lt;secureConversationBootstrap authenticationMode="UserNameForSslNegotiated" messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10"&gt;
                  &lt;localClientSettings maxClockSkew="23:59:59" /&gt;
                  &lt;localServiceSettings maxClockSkew="23:59:59" /&gt;
             &lt;/secureConversationBootstrap&gt;                   
              &lt;localClientSettings maxClockSkew="23:59:59" /&gt;
              &lt;localServiceSettings maxClockSkew="23:59:59" /&gt;
          &lt;/security&gt;
          &lt;binaryMessageEncoding/&gt;
          &lt;tcpTransport transferMode="Buffered" portSharingEnabled="true" maxReceivedMessageSize="65536" hostNameComparisonMode="StrongWildcard"/&gt;
        &lt;/binding&gt;
      &lt;/customBinding&gt;
  </code></pre>
  
  <p>Behavior:</p>
  
  <pre><code>&lt;behavior name="SampleBehavior"&gt;
        &lt;serviceMetadata httpGetEnabled="false" /&gt;
        &lt;serviceDebug includeExceptionDetailInFaults="true" httpHelpPageEnabled="true" httpsHelpPageEnabled="true" /&gt;
          &lt;serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="Sample.Tools.CustomAuthorizationManager, Sample"&gt;
          &lt;authorizationPolicies&gt;
            &lt;add policyType="Sample.Tools.CustomAuthorizationPolicy, Sample" /&gt;
          &lt;/authorizationPolicies&gt;
        &lt;/serviceAuthorization&gt;
        &lt;serviceCredentials&gt;
          &lt;serviceCertificate findValue="MySample" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName" /&gt;
          &lt;userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="Sample.Tools.CustomUserNameValidator, Sample" /&gt;
        &lt;/serviceCredentials&gt;
        &lt;serviceThrottling maxConcurrentCalls="2147483647" maxConcurrentSessions="2147483647" maxConcurrentInstances="2147483647" /&gt;
      &lt;/behavior&gt;
  </code></pre>
  
  <p>Services:</p>
  
  <pre><code>&lt;services&gt;
      &lt;service behaviorConfiguration="SampleBehavior"
      name="Sample.SampleService"&gt;
      &lt;endpoint address="" 
                binding="customBinding" 
                bindingConfiguration="SampleBinding"
                name="MyServiceEndpoint" 
                contract="Sample.ISampleService"&gt;
          &lt;identity&gt;
              &lt;dns value="localhost" /&gt;
          &lt;/identity&gt;
      &lt;/endpoint&gt;
  
      &lt;endpoint address="mex" 
                binding="mexTcpBinding" 
                bindingConfiguration=""
                name="MyServiceMexTcpBidingEndpoint" 
                contract="IMetadataExchange" /&gt;
          &lt;host&gt;
              &lt;baseAddresses&gt;
                  &lt;add baseAddress="net.tcp://localhost:809/SampleService.svc" /&gt;
              &lt;/baseAddresses&gt;
          &lt;/host&gt;
      &lt;/service&gt;
  &lt;/services&gt;    
  </code></pre>
  
  <p>I'm pretty much stuck here and there is very little to find regarding this issue.</p>