2011-11-16 62 views
1

我想用WCF(VS2010)構建兩個webservices。 一個Web服務運行正常,但是當我添加第二個Web服務,然後我得到了以下錯誤:找不到IMetadataExchange

The contract name 'IMetadataExchange' could not be found in the list of contracts implemented by the service {0}. Add a ServiceMetadataBehavior to the configuration file or to the ServiceHost directly to enable support for this contract.

第二web服務本質上是第一個副本。所以我不知道爲什麼我得到這個錯誤以及如何解決這個問題。任何人都知道問題可能是什麼?

這是我App.config文件:

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 

    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. --> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="WcfEmguCV1.Service1Behavior" name="WcfEmguCV1.EvalService"> 
     <endpoint address="" binding="wsHttpBinding" contract="WcfEmguCV1.IEvalService"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfEmguCV1/Service1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
     <service name="WcfEmguCV1.Image"> 
     <endpoint binding="wsHttpBinding" bindingConfiguration="" contract="WcfEmguCV1.IIMage"> 
      <identity> 
      <dns value="localhost" /> 
      </identity> 
     </endpoint> 
     <endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfEmguCV1/Service2/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WcfEmguCV1.Service1Behavior"> 
      <!-- 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> 

     <behavior name="WcfEmguCV1.Service2Behavior"> 
      <!-- 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> 
    </system.serviceModel> 

</configuration> 

回答

1

,我發現我的問題。首先,我通過「編輯WCF配置」選項向App.config添加新數據。 (右鍵點擊App.config文件,你會看到這個選項)。

由於第一個Web服務配置已經默認在那裏,我不得不添加一個新的。所以我試圖輸入完全相同的數據。但有些東西不能通過該方法添加。

,因爲當我在我的XML文件了仔細一看,我注意到我錯過本作的第二個Web服務:

<service behaviorConfiguration="WcfEmguCV1.Service1Behavior" ...> 

因此,所有我要做的就是將它添加到「服務的第二個節點」。

behaviorConfiguration =「WcfEmguCV1.Service2Behavior」