Brian
Brian

Reputation: 1459

Unable to connect to WCF service from windows service

I have a WCF service hosted on a remote machine. On my local machine I have a WPF application and a windows service that I want to be able to connect to the WCF service. The WPF application connects and communicates fine, but for some reason the windows service won't connect. The app.config files for both of them are identical and the code to make the connection is the same in both. Is there any reason why a windows service would not be able to connect?

Here is the exception I am getting:

The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:01:14.9900000'.

The strange thing about this is the exception is thrown within 5 seconds, not after the 1:15 that the timeout is set to.

Here is the 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>

The tracing doesn't seem to reveal anything useful as far as I can tell.

Upvotes: 2

Views: 6446

Answers (1)

Sixto Saez
Sixto Saez

Reputation: 12680

Check the account your Windows Service is running under. Since you're accessing a network resource, you'll need a domain account that has sufficient rights to access it (as your logged in user account does).

Upvotes: 8

Related Questions