2011-06-17 149 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

相關問題