开发者

WCF windows service, Service metadata may not be accessible

Hi a have WCF service libary with this configuration:

<?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="开发者_Go百科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>

If I build it in debug, everything works fine on localhost. But if I make a Windows Service library with the same configuration:

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

    }

Install it with InstallUtil and start it:

WCF windows service, Service metadata may not be accessible

but error:

WCF windows service, Service metadata may not be accessible


I suspect this line is the culprit.

_host = new ServiceHost(typeof(TokenService)); 

TokenService is your Windows service class, not your WCF service class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜