WCF SocketException

故事扮演 提交于 2019-12-11 10:25:10

问题


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.

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: No connection could be made because the target machine actively refused it 127.0.0.1:8732

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

What's wrong? Thank you in advance.

EDIT: 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>

回答1:


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.

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.

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

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




回答2:


Have you tried using something like WireShark? Running it at both endpoint is a good way to troubleshoot socket woes.



来源:https://stackoverflow.com/questions/9710351/wcf-socketexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!