【问题标题】:Hosting WCF in console application : Metadata publishing for this service is currently disabled在控制台应用程序中托管 WCF:此服务的元数据发布当前已禁用
【发布时间】:2014-03-15 19:02:00
【问题描述】:

我有 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>

【问题讨论】:

  • 如果您将“基本”附加到控制台应用程序配置中的 ServiceAddress 设置,如下所示:&lt;add key="ServiceAddress" value="http://X:Port/InboundMessage.Service/basic" /&gt;
  • 它抛出 HTTP 400 错误请求。查看我对原始问题的编辑。
  • 为什么不正确?你想达到什么目标?
  • 我是 WCF 新手,但如果我错了,请纠正我。我的理解是,如果我在服务中有 标记,并且宿主项目配置在应用程序配置中有引用。托管服务应该足够了

标签: c# .net web-services wcf web-hosting


【解决方案1】:

配置(包括 WCF)必须在所执行程序集的配置文件中。在您的情况下,它必须在控制台应用程序的配置文件中。

仅将 WCF 添加到控制台应用程序使用的库之一的配置中是不够的。这有两个原因:

  1. 在构建主(可执行)程序集时,库的配置默认不会复制到输出文件夹中。

  2. 即使它被复制,它也会有一个错误的名称。 WCF 配置是从与正在执行的程序集同名的配置文件中读取的。

这不仅仅针对 WCF,它也是 .NET 的工作方式。

【讨论】:

  • 谢谢..这回答了我的问题。
猜你喜欢
  • 2011-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多