1

我正在 VS2010 中开发 WCF 应用程序。当我使用 in-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>
4

2 回答 2

4

已发布,因此用户不必阅读 13 条评论

在这种情况下,问题在于用户正在运行多项目解决方案。在这种情况下,任何正在运行的项目都是其配置文件重要的项目。

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

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

这是 Web 服务新手常犯的错误,没有什么好羞愧的。

于 2012-03-14T22:23:30.047 回答
0

您是否尝试过使用类似WireShark的东西?在两个端点上运行它是解决套接字问题的好方法。

于 2012-03-14T21:15:12.187 回答