wpf TCP 错误代码 10061:无法建立连接,因为目标机器主动拒绝它 127.0.0.1:8732
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25005813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8732
提问by Hoang Minh
I have a wcf service application using windows service. Additionally, I have a wpf app that connects to the wcf service. I have been unable to open the wpf program. This is the error I get when I attempt to open the wpf app from Visual Studio by hitting F5 in debug mode:
我有一个使用 Windows 服务的 wcf 服务应用程序。此外,我有一个连接到 wcf 服务的 wpf 应用程序。我一直无法打开 wpf 程序。这是我尝试通过在调试模式下按 F5 从 Visual Studio 打开 wpf 应用程序时遇到的错误:
mscorlib.dll but was not handled in user code
Additional information: Could not connect to net.tcp://localhost:8732/Design_Time_Addresses/NextGenService/SimSession/. The connection attempt lasted for a time span of 00:00:02.2590000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8732.
I do have both Http and Non-http activation options on under the wcf activation node of selected features. all 3 services to do with net.tcp are running: Net Pipe Listener Adapter, Net.Tcp Listener Adapter, Net.Tcp Port Sharing Service.
在所选功能的 wcf 激活节点下,我确实有 Http 和非 http 激活选项。与 net.tcp 相关的所有 3 个服务都在运行:Net Pipe Listener Adapter、Net.Tcp Listener Adapter、Net.Tcp 端口共享服务。
app.config for the server:
服务器的 app.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="logFile" value="C:\ProgramData\SimSci\Log\server.log"/>
<add key="SecureFolder" value="..\..\..\..\..\SharedComponents"/>
<!--<add key="logLevel" value="Debug"/>-->
<!--<add key="VariableConnection" value="Connected"/>-->
</appSettings>
<system.diagnostics>
<sources>
<!--Add below switch when need trace on developer system -->
<!--switchValue="Warning, ActivityTracing"-->
<source name="System.ServiceModel.MessageLogging" switchValue="Off">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type=""/>
</add>
<add name="ServiceModelMessageLoggingListener">
<filter type=""/>
</add>
</listeners>
</source>
<!--Add below switch when need trace on developer system -->
<!--switchValue="Warning, ActivityTracing"-->
<source name="System.ServiceModel" switchValue="Off" propagateActivity="true">
<listeners>
<add type="System.Diagnostics.DefaultTraceListener" name="Default">
<filter type=""/>
</add>
<add name="ServiceModelTraceListener">
<filter type=""/>
</add>
</listeners>
</source>
</sources>
<sharedListeners>
<add initializeData="..\..\app_messages.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelMessageLoggingListener" traceOutputOptions="Timestamp">
<filter type=""/>
</add>
<add initializeData="..\..\app_tracelog.svclog" type="System.Diagnostics.XmlWriterTraceListener, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" name="ServiceModelTraceListener" traceOutputOptions="Timestamp">
<filter type=""/>
</add>
</sharedListeners>
</system.diagnostics>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- tempdt timeout values-->
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ISimSession" closeTimeout="00:10:00" openTimeout="00:10:00" receiveTimeout="00:10:00" sendTimeout="00:10:00" transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="104857600" maxConnections="10" maxReceivedMessageSize="104857600">
<readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false"/>
<!--<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>-->
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="SimCentral.Server.SimSession">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ISimSession" contract="NextGenServices.Contract.ISimSessionService.ISimSession">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8732/Design_Time_Addresses/NextGenService/SimSession/"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="false"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<gcServer enabled="true"/>
<gcConcurrent enabled="true"/>
</runtime>
</configuration>
app.config for the client
客户端的 app.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ContractType" value="ISimSession"/>
<add key="ISimSessionNameSpaceVersion" value="http://Invensys.com/SimSci-Esscor/NextGen-Sim/1.0.32.6e"/>
<add key="Scope" value="aa.soa://SimSession"/>
<add key="UseASBHost" value="0"/>
<add key="logFile" value="C:\ProgramData\SimSci\Log\client.log"/>
<add key="logLevel" value="Debug"/>
</appSettings>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_ISimSession" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" transactionFlow="true" transferMode="Buffered" transactionProtocol="OleTransactions" hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288" maxBufferSize="104857600" maxConnections="10" maxReceivedMessageSize="104857600">
<readerQuotas maxDepth="32" maxStringContentLength="104857600" maxArrayLength="104857600" maxBytesPerRead="104857600" maxNameTableCharCount="104857600"/>
<reliableSession ordered="true" inactivityTimeout="00:10:00"/>
<!--<security mode="Transport">
<transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
<message clientCredentialType="Windows" />
</security>-->
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://localhost:8732/Design_Time_Addresses/NextGenService/SimSession/" binding="netTcpBinding" bindingConfiguration="NetTcpBinding_ISimSession" contract="SimSessionService.ISimSession" name="NetTcpBinding_ISimSession">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
</client>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
I tried all the suggestions on the Internet, but none is working for me. Is there anything else that I can do to fix this problem ? Thank you.
我尝试了互联网上的所有建议,但没有一个对我有用。我还能做些什么来解决这个问题?谢谢你。
回答by VipinM
I also faced the same issue.
我也面临同样的问题。
Please check your windows service OnStart method for following line.
请检查您的 Windows 服务 OnStart 方法以获取以下行。
serviceHost = new ServiceHost(typeof(**WCFService**));
Make sure this WCFService is actually you WCF service contract class and not the windows service class. There are posts over the internet which creates this ServiceHost for windows service and not WCFService, which is not correct.
确保此 WCFService 实际上是您的 WCF 服务合同类,而不是 Windows 服务类。互联网上有一些帖子为 Windows 服务而不是 WCFService 创建了这个 ServiceHost,这是不正确的。

