WCF Windows服务,可能无法访问服务元数据

时间:2011-06-17 09:12:26

标签: wcf windows-services

您有使用此配置的WCF服务库:

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>
    <services>
      <service behaviorConfiguration="Default" name="ComDocs.ControlServerServiceLibary.Concrete.TokenService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8080/TokenService" />
          </baseAddresses>
        </host>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <endpoint address="basic" binding="basicHttpBinding" contract="ComDocs.ControlServerServiceLibary.Abstract.ITokenService" />        
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="Default">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

如果我在调试中构建它,一切都可以在localhost上正常工作。但是,如果我使用相同的配置创建一个Windows服务库:

public partial class TokenService : ServiceBase
    {
        ServiceHost _host = null;

        public TokenService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            Trace.WriteLine("Starting Token Service...");

            _host = new ServiceHost(typeof(TokenService));        
            _host.Open();
        }

        protected override void OnStop()
        {
            Trace.WriteLine("Shutting down Token Service...");

            if (_host != null)
            {
                _host.Close();
                _host = null;
            }
        }

    }

使用InstallUtil安装并启动它:

enter image description here

但错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

我怀疑这条线是罪魁祸首。

_host = new ServiceHost(typeof(TokenService)); 

TokenService是您的 Windows 服务类,而不是 WCF 服务类。

相关问题