TCP错误代码10061:无法建立连接,因为目标计算机主动拒绝它127.0.0.1:8732

时间:2014-07-28 23:15:55

标签: c# wpf wcf

我有一个使用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.

我在所选功能的wcf激活节点下都有Http和非http激活选项。所有与net.tcp有关的3项服务都在运行:Net Pipe Listener Adapter,Net.Tcp Listener Adapter,Net.Tcp Port Sharing Service。

服务器的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

<?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>

我尝试了互联网上的所有建议,但没有一个对我有用。我还能做些什么来解决这个问题吗?谢谢。

1 个答案:

答案 0 :(得分:0)

我也面临同样的问题。

请检查您的Windows服务OnStart方法以获取以下行。

serviceHost = new ServiceHost(typeof(**WCFService**));

确保此WCFService实际上是您的WCF服务合同类而不是Windows服务类。互联网上有帖子为Windows服务而不是WCFService创建了这个ServiceHost,这是不正确的。