WCF SocketException

本文关键字:SocketException WCF | 更新日期: 2023-09-27 18:27:45

我正在VS2010中开发一个WCF应用程序。当我使用IDE中的调试器来运行主机应用程序和客户端时,一切都能正常工作。

但是,当我手动运行这两个可执行文件(转到/bin/Debug/文件夹)时,我从客户端得到以下异常:

System.Net.Sockets.SocketException:由于目标计算机主动拒绝,无法建立连接127.0.0.1:8732

奇怪的是,在app.config文件中,我指定使用端口5000,而不是8732。

怎么了?提前谢谢。

编辑:这是主机应用程序的app.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <compilation debug="true" />
  </system.web>
  <!-- When deploying the service library project, the content of the config file must be added to the host's 
  app.config file. System.Configuration does not support config files for libraries. -->
  <system.serviceModel>
    <services>
      <service name="WCFServiceLibrary.SavalotServiceObject">
        <endpoint address="" binding="wsHttpBinding" contract="WCFServiceLibrary.ISavalotService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:5000/Design_Time_Addresses/WCFServiceLibrary/SavalotServiceObject/" />
          </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="True"/>
          <!-- 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="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

WCF SocketException

发布这样用户就不必通过13条评论

在这种情况下,问题是用户正在运行多项目解决方案。在这种情况下,无论哪个项目正在运行,其配置文件都很重要。

如果运行WcfService,则需要包含服务的项目将其web.config文件配置为使用正确的端口。

如果您正在测试WcfService,则需要将测试项目的app.config文件配置为使用正确的端口。

这是那些刚接触网络服务的人经常犯的错误,没什么好羞愧的。

你试过使用WireShark这样的东西吗?在两个端点上运行它是解决套接字问题的好方法。