2012-03-15 106 views
2

我有一個WCF服務託管在遠程機器上。在我的本地機器上,我有一個WPF應用程序和一個Windows服務,我希望能夠連接到WCF服務。 WPF應用程序可以很好地連接和通信,但由於某些原因,Windows服務將無法連接。它們兩個的app.config文件都是相同的,並且用於建立連接的代碼在兩者中都是相同的。是否有任何理由爲什麼Windows服務將無法連接?無法連接到Windows服務的WCF服務

這是我收到的例外:

套接字連接被中止。這可能是由於處理您的消息時發生錯誤或遠程主機超出了接收超時時間,或者是由於基礎網絡資源問題造成的。本地套接字 超時時間爲'00:01:14.9900000'。

奇怪的是,這個異常是在5秒內拋出,而不是在超時設置爲1:15之後拋出。

這裏是在app.config:

<?xml version="1.0"?> 
<configuration> 
    <appSettings> 
    <add key="ServiceIP" value="127.0.0.1"/> 
    </appSettings> 
    <startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> 
    </startup> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <probing privatePath="lib" /> 
    </assemblyBinding> 
    </runtime> 
    <system.serviceModel> 
    <bindings> 
     <netTcpBinding> 
     <binding name="NetTcpBindingEndpoint" closeTimeout="00:01:00" 
      openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:01:15" 
      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:8731/WCFService/" binding="netTcpBinding" 
     bindingConfiguration="NetTcpBindingEndpoint" contract="WCFService.IWCFService" 
     name="NetTcpBindingEndpoint"> 
     <identity> 
      <dns value="localhost" /> 
     </identity> 
     </endpoint> 
    </client> 
    </system.serviceModel> 
    <system.diagnostics> 
    <sources> 
     <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true"> 
     <listeners> 
      <add name="traceListener" type="System.Diagnostics.XmlWriterTraceListener" initializeData="Traces.svclog"/> 
     </listeners> 
     </source> 
    </sources> 
    </system.diagnostics> 
</configuration> 

似乎是跟蹤並不至於我可以告訴透露任何有用的東西。

回答

8

檢查您的Windows服務正在運行的帳戶。由於您正在訪問網絡資源,因此您需要一個擁有足夠權限訪問它的域帳戶(如您登錄的用戶帳戶所做的那樣)。