2010-05-17 55 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