[英]How to get rid of “Metadata publishing for this service is currently disabled” in WCF
[英]WCF Service Library (IIS): Metadata publishing for this service is currently disabled
我收到此錯誤,無法撼動。 這個問題類似於這個SO問題,還有很多其他問題,更不用說頁面本身了。
是的,我完全認識到namespace
和service name
必須完全匹配。 我現在讀到那筆錢不折不扣。
我有一個WCF服務庫,該庫正在IIS中運行。 該服務器是Windows Server 2016 Standard版。 我改名App.config
到Web.config
,盡管我試圖為App.config
。 我嘗試了每個似乎無數的配置,並且仍然是相同的錯誤。 是的,我嘗試添加綁定並指定basicHttpBinding
。
Web.Config中
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyTesterLibrary.MyTester" behaviorConfiguration="MetadataBehavior">
<endpoint address="" binding="wsHttpBinding" contract="MyTesterLibrary.IMyTester" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" httpHelpPageEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
主班
namespace MyTesterLibrary
{
public class MyTester : IMyTester
{
public string GetVersionInfo()
{
Backup.GetVersionInfo(out string response);
return response;
}
}
}
接口類別
namespace MyTesterLibrary
{
[ServiceContract]
public interface IMyTester
{
[WebInvoke(Method = "GET", RequestFormat = WebMessageFormat.Xml, ResponseFormat = WebMessageFormat.Xml, UriTemplate = "/GetVersionInfo")]
[OperationContract]
string GetVersionInfo();
}
}
ProductServiceHost.svc
<%@ ServiceHost Service="MyTesterLibrary.MyTester" %>
我按照另一個站點上的說明進行操作,並創建了IIS站點。 此屏幕快照說明了一切。
我知道在所引用的SO文章中,該人員堅持認為問題出在IIS中,而事實並非如此,但是我的問題肯定是這樣。 我只是又一次嘗試了basicHttpBinding
。
在asp.net論壇上的這個問題也很有趣。 我本能地將App.config
重命名為Web.config
並重建了DLL。 IIS不會讀取“ App.config”。
思考?
最后引用的文章指出了問題,我的猜想是正確的。 我在寫的很好時就把這個問題留在這里,但更重要的是,沒有說明重要的事實。
Visual Studio
或C#
沒有嵌入Web.config,或者IIS沒有從DLL中提取文件。 我讀過的所有文章都說要寫一個SVC文件,將DLL放在bin文件中,但是都忽略了兩個關鍵信息。
將App.config
復制到“ Web.config”。
將Web.config
的副本放置在與SVC文件相同的文件夾中。
無需刷新IIS中的網站,但是必須刷新瀏覽器頁面。
我希望這個答案對某人有幫助,因為我確實受了苦,幾乎沒有得到。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.