WCF - 无法获取元数据
Posted
技术标签:
【中文标题】WCF - 无法获取元数据【英文标题】:WCF - Cannot obtain Metadata 【发布时间】:2012-05-08 19:32:54 【问题描述】:它在使用 IIS 7 的 Intranet 中运行,只要我在 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。
【问题讨论】:
【参考方案1】:移除 MEX 端点并离开。 Mex 端点需要启用匿名身份验证。
【讨论】:
【参考方案2】:Javi 是对的,我必须删除 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 hosted WCF-service + Windows auth in IIS + TransportCredentialOnly/Windows auth in basicHttpBinding
【讨论】:
以上是关于WCF - 无法获取元数据的主要内容,如果未能解决你的问题,请参考以下文章
添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据。 WCF 错误
WCF 测试客户端:添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据