Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在控制台应用程序中承载WCF:此服务的元数据发布当前已禁用_C#_.net_Web Services_Wcf_Web Hosting - Fatal编程技术网

C# 在控制台应用程序中承载WCF:此服务的元数据发布当前已禁用

C# 在控制台应用程序中承载WCF:此服务的元数据发布当前已禁用,c#,.net,web-services,wcf,web-hosting,C#,.net,Web Services,Wcf,Web Hosting,我有一个WCF应用程序,我使用一个控制台应用程序在本地托管它。我在下面添加了配置 服务等级 namespace InboundMessage.Service; Operator: IOperator { } namespace InboundMessage.Service; IOperator { } App.config <configuration> <system.web> &

我有一个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的工作方式

    如果在控制台应用程序配置中将“basic”附加到ServiceAddress设置中,会怎么样:
    它抛出HTTP 400错误请求。请参阅我对原始问题的编辑。为什么不正确?你想实现什么?我是WCF新手,但如果我错了,请纠正我。我所理解的是,如果我在服务中有标签,并且主机项目配置在应用程序配置中有引用。主持一次服务就足够了谢谢你这回答了我的问题。