2010-05-17 56 views
1

在托管我在IIS上称为“SimpleWCF”的WCF服务;我在浏览器中手动浏览时遇到以下错误;
元数据错误 - WCF

无法在由服务SimpleWCF实施的合同列表中找到合同名称'IMetadataExchange'。将ServiceMetadataBehavior添加到配置文件或直接添加到ServiceHost以启用对此合同的支持。


我无法理解这个错误的原因[仍然是新的。
这是我的配置文件;

<configuration> 
    <system.serviceModel> 
    <behaviors> 
    <endpointBehaviors> 
    <behavior name=""> 
    <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name=""> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 
<bindings> 
    <basicHttpBinding> 
    <binding name="LargeData" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647"> 
     <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/> 
     <security mode="None"> 
     </security> 
    </binding> 
    </basicHttpBinding> 
</bindings> 
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/> 
<services> 
    <service name="SimpleWCF"> 
    <endpoint address="http://localhost/Sample/SimpleWCF.svc" binding="basicHttpBinding" bindingConfiguration="LargeData" contract="SimpleWCF"/> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 
    </system.serviceModel> 
    <system.web> 
<compilation debug="true"/> 
    </system.web> 
</configuration> 

回答

2

在你的配置,你需要给有效到你的行为!

<behaviors> 
    <endpointBehaviors> 
    <behavior name="webBehavior"> 
    <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
    <serviceBehaviors> 
    <behavior name="serviceBehavior"> 
     <serviceMetadata httpGetEnabled="true"/> 
     <serviceDebug includeExceptionDetailInFaults="false"/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

,并将它们从<service>标签,你需要参考这种行为:

<service name="SimpleWCF" behaviorConfiguration="serviceBehavior"> 

使它成为活跃。

如果你在.NET 4/WCF 4,你还可以定义默认行为 - 但你需要完全离开了name=属性:

现在每个端点将得到终结点行为,并且每个服务都将获得服务行为。

+0

(+1)你是男人的标志。我有同样的问题,直到我一起删除名称属性。 – capdragon 2011-09-09 17:44:44