2012-03-15 94 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服务正在运行的帐户。由于您正在访问网络资源,因此您需要一个拥有足够权限访问它的域帐户(如您登录的用户帐户所做的那样)。

相关问题