Hosting WCF in console application : Metadata publishing for this service is currently disabled

StackOverflow https://stackoverflow.com/questions/22428351

Вопрос

I have WCF application and I am hosting it locally using a console application. I added the configuration below.

Service class

    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 is a console application that is built and installed in my local machine. config file has address to the service.

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

I keep getting Metadata publishing for this service is currently disabled. Am I missing something in my settings. Thank you for your time.

EDIT

It seems to work only if I add the below in the Host configuration but it doesn't seem the right way to host a service.

    <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>
Это было полезно?

Решение

The configuration (WCF included) has to be in the config file of the assembly that is executed. In your case, it has to be in the config file of the console application.

It is not enough that the WCF is added to the configuration of one of the libraries that the console application uses. This it for two reasons:

  1. Configuration of the libraries is by default not copied into the output folder when you build the main (executable) assembly.

  2. Even if it was copied, it would have a wrong name. WCF configuration is read from the config file that has the same name as the executing assembly.

This is not specific to just WCF, it's the way .NET works.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top