2016-07-11 108 views
0

我有一個非常奇怪的問題,使用WCF的3層客戶端/服務器應用程序。無法訪問託管在Windows服務中的WCF

首先,我有一個服務窗口,它承載了basicHttpBinding中的WCF服務。這是服務器的app.config:

<?xml version="1.0"?> 
<configuration> 
    <system.serviceModel> 
     <services> 
      <service name="Business.BSServiceManagement" behaviorConfiguration="myServiceBehave"> 
       <host> 
        <baseAddresses> 
         <add baseAddress="http://localhost:35001"/> 
        </baseAddresses> 
       </host> 
       <endpoint address="/Clients" binding="basicHttpBinding" name="Clients" contract="Contracts.BusinessFacade.IBFClientManagement"/> 
       <endpoint address="/Users" binding="basicHttpBinding" name="Users" contract="Contracts.BusinessFacade.IBFUserManagement"/> 
       <endpoint address="/Licences" binding="basicHttpBinding" name="Licences" contract="Contracts.BusinessFacade.IBFLicenceManagement"/> 
      </service> 
     </services> 
     <behaviors> 
      <serviceBehaviors> 
       <behavior name="myServiceBehave"> 
        <serviceMetadata httpGetEnabled="true"/> 
        <serviceDebug includeExceptionDetailInFaults="true"/> 
       </behavior> 
      </serviceBehaviors> 
     </behaviors> 
    </system.serviceModel> 
</configuration> 

此服務被部署在DMZ中的服務器上,我從我的電腦訪問(在Firefox中,如果我把與端口號服務地址)

其次,我有一個winform客戶端應用程序,它使用ChannelFactory來使用服務。

這是客戶端的app.config:

<?xml version="1.0"?> 
<configuration> 
    <system.serviceModel> 
     <client> 
      <endpoint address="http://192.168.128.1:35001/Clients" binding="basicHttpBinding" name="Clients" contract="Contracts.BusinessFacade.IBFClientManagement"/> 
      <endpoint address="http://192.168.128.1:35001/Users" binding="basicHttpBinding" name="Users" contract="Contracts.BusinessFacade.IBFUserManagement"/> 
      <endpoint address="http://192.168.128.1:35001/Licences" binding="basicHttpBinding" name="Licences" contract="Contracts.BusinessFacade.IBFLicenceManagement"/> 
     </client> 
    </system.serviceModel> 
</configuration> 

當調試客戶端應用程序,一切完美的作品。所以我做了一個安裝項目部署多臺計算機上的應用程序,但是當我執行應用程序的EXE(安裝或直接在斌/釋放),我有一個這樣的錯誤消息:

There was no endpoint listening at http://192.168.128.1:35001/Users... 

內部異常說:

無法連接到遠程服務器

我嘗試添加MEX終結,改變端口號,檢查服務器和客戶端計算機的防火牆,我不明白問題出在哪裏。

感謝您的幫助。

編輯1:

經過多次試驗我在發佈的EXE在調試EXE同樣的問題,但沒有。

如果我執行調試exe文件一切正常,但釋放exe文件返回錯誤信息。

+0

試圖瞭解你的調試配置。你的baseAddress節點是'localhost'是你的開發機器上本地運行的服務嗎? – leetibbett

+0

不,我將服務安裝在DMZ中的另一臺計算機上,並且我只在我的機器上執行了調試客戶端,並且完美地工作。但是當我在我的機器上安裝客戶端時,它不起作用 – user1069516

+0

VS通常以管理員身份運行,如果以管理員身份執行客戶端,該怎麼辦?你添加了客戶端exe的防火牆設置嗎? – leetibbett

回答

0

問題在於您的服務。

確保服務已啓動並正在運行。

一旦啓動服務,瀏覽URL(例如:localhost:8080/example),以確保服務運行正常。

將Service Reference添加到客戶端應用程序時,它會自動生成app.config文件中的端點。

當您將安裝程序添加到客戶端項目時,請確保它已成功建立。

當你安裝它時,它應該適合你。

+0

您的所有觀點都可以,但我沒有在客戶端應用程序中添加服務參考,我使用ChannelFactory – user1069516

+0

在服務配置文件中定義內的<端點地址>。 在客戶端應用程序中,在類中定義端點地址,而不是配置文件。 ex: EndpointAddress address = new EndpointAddress(「http:// localhost:1212/example」); factory = new DuplexChannelFactory (ctx,binding,address); – venkk

+0

這應該起作用。 – venkk

相關問題