首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> .NET 網頁程式設計 >> 關於.NET

WCF 服務顯示「當前已禁用此服務的中繼資料發布」解決方法

     編輯:關於.NET

瀏覽 .svc 時出現:「當前已禁用此服務的中繼資料發布」。原因:<serviceMetadata httpGetEnabled="true" /> 未設定或未掛載至服務行為。

修正步驟

  1. 在 <system.serviceModel> 中加入行為設定:
<behaviors>
  <serviceBehaviors>
    <behavior name="myBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
  </serviceBehaviors>
</behaviors>
  1. 在服務定義中套用該行為:
<services>
  <service name="MyNamespace.MyService" behaviorConfiguration="myBehavior">
    <endpoint address="" binding="basicHttpBinding" contract="MyNamespace.IMyService" />
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
</services>

關鍵點

  • behaviorConfiguration 名稱必須與 <behavior name="..."> 完全一致。
  • 必須加入 mexHttpBinding 端點(address="mex"),否則雖啟用 httpGetEnabled 仍無法匯入中繼資料。
  • HTTPS 環境需同時設定 httpsGetEnabled="true" 並提供 mexHttpsBinding 端點。

驗證

瀏覽 https://host/Service.svc?wsdl 或 https://host/Service.svc/mex 應能正常回傳 WSDL/中繼資料。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved