2011-06-17 109 views
1

喜一有WCF服务libary此配置:WCF Windows服务,服务元数据可能无法访问

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

如果我在调试构建它,一切都运行在本地主机上的罚款。但是,如果我做一个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

您是否已将上述配置复制到服务的app.config中? – 2011-06-17 09:15:41

+0

@ Richard-Blewett是的,我将app.config从服务库文件复制到windows服务项目中 – 2011-06-17 09:54:36

+0

由于您更改了正在监听的进程,防火墙可能会阻止端口8080的请求? – 2011-06-17 10:08:02

回答

1

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

_host = new ServiceHost(typeof(TokenService)); 

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

+0

戴维斯thx男人! – 2011-06-20 07:25:50