WCF 套接字异常 [英] WCF SocketException

查看:63
本文介绍了WCF 套接字异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VS2010 中开发 WCF 应用程序.当我使用 IDE 内调试器运行主机应用程序和客户端时,一切都按预期工作.

I'm developing a WCF application in VS2010. When I use the in-IDE debugger to run the host application and the client, everything works as intended.

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

However, when I run the two executables manually (going to the /bin/Debug/ folders), I get the following exception from the client:

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

System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:8732

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

The odd thing is, in the app.config file I'm specifying to use port 5000, not 8732.

怎么了?提前致谢.

这是宿主应用程序的 app.config:

Here is the app.config for the host application:

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

推荐答案

已发布,因此用户无需浏览 13 条评论

POSTED SO USERS DON'T HAVE TO GO THROUGH 13 COMMENTS

在这种情况下,问题在于用户正在运行多项目解决方案.在这种情况下,运行哪个项目就是其配置文件重要的项目.

In this case, the problem was that the user was running a multi-project Solution. In that case, whichever project is being run is the project whose config file matters.

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

If you're running the WcfService, you'll need the project with the service in it to have its web.config file configured to use the right ports.

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

If you're testing the WcfService, you'll need the test project to have its app.config file configured to use the right ports.

这是 Web 服务新手常犯的错误,没有什么可羞耻的.

This is a common error those new to webservices make and is nothing to be ashamed of.

这篇关于WCF 套接字异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆