2011-08-19 33 views
1

無法從客戶機訪問WCF服務無法從客戶機訪問WCF服務

  • 我有三個項目:WCF服務(VS-2008),Windows服務(VS-2008),客戶端(VS- 2005)
  • WCF服務具有NetTcpBinding的
  • 此服務託管作爲Windows服務,而不是在IIS

的基址既服務(WCF和Windows)是

net.tcp://localhost:8010/WCFService.Service1/ 

現在,當我添加服務參考客戶端項目,該項目是VS-2005,它更新我的app.config文件

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.serviceModel> 
     <bindings> 
      <netTcpBinding> 
       <binding name="netTcpEndPoint" closeTimeout="00:01:00" openTimeout="00:01:00" 
        receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="false" 
        transferMode="Buffered" transactionProtocol="OleTransactions" 
        hostNameComparisonMode="StrongWildcard" listenBacklog="10" 
        maxBufferPoolSize="524288" maxBufferSize="65536" maxConnections="10" 
        maxReceivedMessageSize="65536"> 
        <readerQuotas maxDepth="32" maxStringContentLength="8192"   maxArrayLength="16384" 
         maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
        <reliableSession ordered="true" inactivityTimeout="00:10:00" 
         enabled="false" /> 
        <security mode="Transport"> 
        <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" /> 
         <message clientCredentialType="Windows" /> 
        </security> 
       </binding> 
      </netTcpBinding> 
     </bindings> 
     <client> 
      <endpoint address="net.tcp://localhost:8010/WCFService.Service1/" 
       binding="netTcpBinding" bindingConfiguration="netTcpEndPoint" 
       contract="Client.Service1.IService1" 
       name="netTcpEndPoint"> 
       <identity> 
        <servicePrincipalName value="host/server17.domain.com" /> 
       </identity> 
      </endpoint> 
     </client> 
    </system.serviceModel> 
</configuration> 

,並增加了Service1.map文件

<?xml version="1.0" encoding="utf-8"?> 
<ServiceReference> 
    <ProxyGenerationParameters 
     ServiceReferenceUri="net.tcp://server17:8010/WCFService.Service1/" 
     Name="Service1" 
     NotifyPropertyChange="False" 
     UseObservableCollection="False"> 
    </ProxyGenerationParameters> 
    <EndPoints> 
     <EndPoint 
      Address="net.tcp://localhost:8010/WCFService.Service1/" 
      BindingConfiguration="netTcpEndPoint" 
      Contract="Client.Service1.IService1" 
      > 
     </EndPoint> 
    </EndPoints> 
</ServiceReference> 

當我打電話的任何服務方法時,我得到一個錯誤,說明

無法控制nect to net.tcp:// localhost:8010/WCFService.Service1 /。 連接嘗試持續時間跨度爲00:00:02.0063936。 TCP 錯誤代碼10061:無法建立連接,因爲目標機器 主動拒絕它127.0.0.1:8010。

至少它應該是net.tcp://server17:8010/WCFService.Service1/

我已經嘗試與客戶端項目server17更換localhost ......但沒有運氣

我應該怎麼改變,使其工作?請幫忙。

這是我的WCF服務的App.config中是相同的Windows服務的 的app.config:由蒂姆

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <system.web> 
    <compilation debug="true" /> 
    </system.web> 
    <system.serviceModel> 
    <services> 
     <service behaviorConfiguration="WCFService.ServiceBehavior" 
     name="WCFService.Service1"> 
     <endpoint address="" binding="netTcpBinding" bindingConfiguration="" 
      name="netTcpEndPoint" contract="WCFService.IService1" /> 
     <endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" 
      name="mexTcpEndPoint" contract="IMetadataExchange" /> 
     <host> 
      <baseAddresses> 
      <add baseAddress="net.tcp://localhost:8010/WCFService.Service1/" /> 
      </baseAddresses> 
     </host> 
     </service> 
    </services> 
    <behaviors> 
     <serviceBehaviors> 
     <behavior name="WCFService.ServiceBehavior"> 
      <serviceMetadata httpGetEnabled="False" /> 
      <serviceDebug includeExceptionDetailInFaults="False" /> 
     </behavior> 
     </serviceBehaviors> 
    </behaviors> 
    </system.serviceModel> 
</configuration> 
+0

您的服務和您的客戶在同一臺​​機器上運行嗎? 這是一個明確的網絡相關的錯誤,所以我想你的服務沒有運行或不綁定端口8010.打開命令提示符,並嘗試在運行服務的機器上連接「telnet localhost 8010」。如果你沒有連接,你的服務肯定不會聽8010端口。 – Jan

回答

1

的要求在猜測我會檢查三兩件事:

  1. 將服務引用添加到客戶端時,是從net.tcp://localhost:8010/WCFService.Service1/中添加服務引用還是將其從net.tcp://server17:8010/WCFService.Service1/中添加?

  2. 如果您從服務器17添加它,請嘗試使用服務器的完全限定名稱 - 即server17.mydomain.com或其它任何名稱。

  3. 連接錯誤可能與您使用的端點地址有關 - 客戶端正在傳遞serverPrincipalName爲「host/server17.domain.com」,但您嘗試連接到本地主機。

沒有保證上述任何一項是根本原因,但它給你一個開始的地方。

編輯

您指定的baseAddress元素的locahost,但你不指定在endpiont元素的地址屬性什麼。這可能就是爲什麼它仍然會去localhost。

修改配置文件爲您服務,請更改baseAddress到:

<baseAddresses> 
    <add baseAddress="net.tcp://server17:8010/WCFService.Service1/" /> 
</baseAddresses> 

或刪除baseAddresses並在端點指定地址:

<endpoint address="net.tcp://server17:8010/WCFService.Service1/" 
      binding="netTcpBinding" 
      bindingConfiguration="" 
      name="netTcpEndPoint" 
      contract="WCFService.IService1" /> 

給一個嘗試。

+0

嗨,tim, 感謝您的回覆。 我已經添加了使用net.tcp:// server17:8010/WCFService.Service1/URI 的引用,正如您所建議的那樣,我也使用了完全限定名稱,但仍然無法正常工作並給出相同的錯誤... 我想知道爲什麼它試圖聯繫localhost而不是server17? 爲什麼即使在我從Server17添加服務引用後,也有本地主機的URI? (你可以從上面給出的配置和映射文件中看到)。 是否與WCF服務中的baseaddress相關 - 指向localhost的app.config? – Bravo

+0

@Bravo - 它可能是相關的。因爲你明確地設置了完全合格的地址,所以我不會想(從我的頭頂開始)。嘗試刪除它,看看是否有竅門。另外,發佈你的服務的app.config文件。 – Tim

+0

好的蒂姆,我已經發布了我的服務的配置文件,請看看問題聲明 – Bravo