WCF - Cannot obtain Metadata

27,077

Solution 1

Remove the MEX endpoint and leave . Mex endpoints require anonymous authentication to be enabled.

Solution 2

Javi was right, I had to remove the mex endpoint and just for the records, this is the final version of the web.config:

<system.serviceModel>
<bindings> 
    <basicHttpBinding> 
        <binding name="basicBinding"> 
            <security mode="TransportCredentialOnly"> 
                <transport clientCredentialType="Windows" /> 
            </security> 
        </binding>
    </basicHttpBinding> 
</bindings> 
<services> 
    <service name="EvalServiceLibrary.EvalService" behaviorConfiguration="ServiceBehavior"> 
        <endpoint address="" binding="basicHttpBinding" bindingConfiguration="basicBinding" contract="EvalServiceLibrary.IEvalService"> 
        </endpoint> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
        <behavior name="ServiceBehavior"> 
            <serviceDebug includeExceptionDetailInFaults="true" /> 
            <serviceMetadata httpGetEnabled="false" />
        </behavior> 
    </serviceBehaviors> 
</behaviors>
</system.serviceModel>

more details here, IIS hosted WCF-service + Windows auth in IIS + TransportCredentialOnly/Windows auth in basicHttpBinding

Share:
27,077
m0dest0
Author by

m0dest0

Updated on April 29, 2020

Comments

  • m0dest0
    m0dest0 about 4 years

    It is running in an Intranet using IIS 7 and it works fine whenever I enable Anonymous Authentication in the IIS Manager. If I disable it and try to run it using wcftestclient then I get the following error,

    Error: Cannot obtain Metadata from http://myserver/testing/eval.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address.  For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error    URI: http://myserver/testing/eval.svc    Metadata contains a reference that cannot be resolved: 'http://myserver/testing/eval.svc'.    The HTTP request is unauthorized with client authentication scheme 'Anonymous'. 
    

    This is my web.config file,

    <system.serviceModel>
    <bindings>
        <wsHttpBinding>
            <binding name="Binding1">
                <security mode="Transport">
                    <transport clientCredentialType="Windows" />
                    <message establishSecurityContext="true" />
                </security>
            </binding>
        </wsHttpBinding>
        <basicHttpBinding>
            <binding name="httpBinding">
                <security mode="Transport">
                    <transport clientCredentialType="Windows" />
                </security>
            </binding>
        </basicHttpBinding>     
    </bindings>
    
    <services>
      <service behaviorConfiguration="ServiceBehavior" name="EvalServiceLibrary.EvalService">
        <endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1" contract="EvalServiceLibrary.IEvalService">
          <identity>
            <dns value="myserver.mydomain.com" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="basic" binding="basicHttpBinding" contract="EvalServiceLibrary.IEvalService" />
      </service>
    </services>
    
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    

    As you can see I'm populating metadata using mexHttpBinding endpoint. So any advice is welcome.

    Thank you, m0dest0.