![](/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.