![](/img/trans.png)
[英]WCF Service Library (IIS): Metadata publishing for this service is currently disabled
[英]Hosting WCF in console application : Metadata publishing for this service is currently disabled
我有WCF應用程序,我使用控制台應用程序在本地托管它。 我在下面添加了配置。
服務類
namespace InboundMessage.Service;
Operator: IOperator {
}
namespace InboundMessage.Service;
IOperator {
}
App.config中
<configuration>
<system.web>
<compilation debug="true">
</compilation>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="InboundMessage.Service.Operator" behaviorConfiguration="meta" >
<endpoint address="basic" binding="basicHttpBinding" contract="InboundMessage.Service.IOperator"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress = "http://X:Port/InboundMessage.Service/"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Host Project是一個在我的本地計算機上構建和安裝的控制台應用程序。 配置文件包含服務的地址。
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="ServiceAddress" value="http://X:Port/InboundMessage.Service/"/>
</appSettings>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
我一直在禁用此服務的元數據發布。 我在設置中遺漏了什么。 感謝您的時間。
編輯
它似乎只有在我在主機配置中添加以下內容時才有效,但它似乎不是托管服務的正確方法。
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="InboundMessage.Service.Operator" behaviorConfiguration="meta" >
<endpoint address="basic" binding="basicHttpBinding" contract="InboundMessage.Service.IOperator"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
配置(包括WCF)必須位於執行的程序集的配置文件中。 在您的情況下,它必須位於控制台應用程序的配置文件中。
將WCF添加到控制台應用程序使用的其中一個庫的配置是不夠的。 這有兩個原因:
在構建主(可執行)程序集時,默認情況下不會將庫的配置復制到輸出文件夾中。
即使它被復制,也會有錯誤的名稱。 從配置文件中讀取WCF配置,該配置文件與正在執行的程序集同名。
這不僅僅是WCF,它是.NET的工作方式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.