WCF - 无法获取元数据(WCF - Cannot obtain Metadata)

2019-07-29 04:39发布

它在使用IIS 7的联网运行,每当我在IIS管理器中启用匿名身份验证它工作正常。 如果我禁用它并尝试使用它wcftestclient然后我得到下面的错误运行,

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'. 

这是我的web.config文件,

<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>

正如你可以看到我使用mexHttpBinding端点填充的元数据。 所以任何意见是值得欢迎的。

谢谢你,m0dest0。

Answer 1:

取出MEX端点和离开。 MEX终结要求匿名身份验证启用。



Answer 2:

哈维是正确的,我不得不删除MEX端点和公正的记录,这是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>

这里更多的细节, IIS托管WCF服务+ Windows验证在IIS + TransportCredentialOnly / Windows验证在basicHttpBinding的



文章来源: WCF - Cannot obtain Metadata