2013-12-13 60 views
0

我已經創建了具有以下配置的服務主機。WCF IMetadataExchange錯誤

<?xml version="1.0"?> 
<configuration> 
    <system.serviceModel> 
    <services> 
     <service name="MathServiceLib.MathService" behaviorConfiguration="myMathServiceBehave"> 
     <host> 
      <baseAddresses> 
      <add baseAddress="http://localhost:9001/MathService"/> 
      <add baseAddress="net.tcp://localhost:9002/MathService"/> 
      </baseAddresses> 
     </host> 
     <endpoint address="http://localhost:9001/MathService" binding="basicHttpBinding" contract="MathServiceLib.IMathService"/> 
     <endpoint address ="net.tcp://localhost:9002/MathService" binding ="netTcpBinding" contract="MathServiceLib.IMathService"/> 
     <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/> 
     <!--<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>--> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="myMathServiceBehave"> 
      <!--<serviceMetadata httpGetEnabled="true"/>--> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 

我不想使用serviceMetadata httpGetEnabled =「真正的」屬性,而不是我想用MEX創建代理結合。現在

當我使用

svcHost = new ServiceHost(typeof(MathServiceLib.MathService)); 
svcHost.Open(); 

我獲得以下錯誤,請幫我啓動服務。

無法在由服務MathService實施的合同列表中找到合同名稱'IMetadataExchange'。將ServiceMetadataBehavior添加到配置文件或直接添加到ServiceHost以啓用對此合同的支持。

+0

你有沒有impl評論'IMetadataExchange'接口(如你的端點定義)?或者你只是想引入另一種連接到IMathService的方式? 也許你錯過了'System.ServiceModel.Description'庫? –

回答

0

根據我的經驗,你需要指定

<serviceMetadata httpGetEnabled="true"/> 

,如果你想使用

<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> 

下面的文章提供了全面的信息和示例:
http://msdn.microsoft.com/en-us/library/ms734765(v=vs.110).aspx
http://www.c-sharpcorner.com/UploadFile/81a718/wcf-service-faqs-part-2/

+0

如果我們指定httpGetEnabled = true,那麼mexHttpBinding端點的意義是什麼? – Dev

+0

下面的StackOverflow Q/A可能有助於提供一些見解... http://stackoverflow.com/questions/2106637/what-is-mexhttpbinding ...關於 – Seymour