无法从Windows服务连接到WCF服务 [英] Unable to connect to WCF service from windows service

查看:98
本文介绍了无法从Windows服务连接到WCF服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有托管在远程机器上的WCF服务。在我的本地机器我有一个WPF应用程序,并且我希望能够连接到WCF服务窗口服务。 WPF应用程序连接和通信正常,但由于某些原因,Windows服务将无法连接。在app.config文件两者都是相同的,而code,使连接在这两个相同的。没有任何理由,为什么一个窗口服务将无法连接?

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?

下面是例外,我得到:

套接字连接被中止。这可以通过一个错误处理您的信息或接收超时引起被超出   远程主机,或者潜在的网络资源问题。本地套接字   超时是00:01:14.9900000

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'.

奇怪的这个是例外是5秒内抛出,而不是1:15,超时被设置为后。

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

下面是在app.config:

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.

推荐答案

检查Windows服务在其下运行的帐户。既然你访问网络资源时,你需要具有足够权限的域帐户来访问它(如您的登录的用户帐户一样)。

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).

这篇关于无法从Windows服务连接到WCF服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆