[英]Unable to connect to WCF service from windows service
我在远程计算机上托管了WCF服务。 在我的本地机器上,我有一个WPF应用程序和一个Windows服务,我希望能够连接到WCF服务。 WPF应用程序连接和通信很好,但由于某种原因,Windows服务将无法连接。 它们的app.config文件是相同的,并且连接的代码在两者中是相同的。 是否有任何理由为什么Windows服务无法连接?
以下是我得到的例外情况:
套接字连接已中止。 这可能是由于处理消息的错误或远程主机超出接收超时或基础网络资源问题引起的。 本地套接字超时为'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>
据我所知,追踪似乎没有揭示任何有用的东西。
检查运行Windows服务的帐户。 由于您正在访问网络资源,因此您需要具有足够权限才能访问它的域帐户(如您登录的用户帐户所做的那样)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.