简体   繁体   English

WCF-没有端点在http localhost上侦听+无法建立连接,因为目标计算机主动拒绝了它=>外部网络

[英]WCF - No endpoint listening at http localhost + No connection could be made because the target machine actively refused it => external network

I have issue with hosing WCF service in console. 我在控制台中托管WCF服务时遇到问题。 Tried to search here but could not find solution of this issue even if it is similar to other issues here. 试图在此处搜索,但即使与此处的其他问题相似,也无法找到此问题的解决方案。

Hosting is very simple. 托管非常简单。

C# - Host C#-主机

WCFSrv = new WCFService();
WCFSrvHost = new ServiceHost(typeof(WCFService));
udaWCFSrvHost.Open();

Config: 配置:

 <system.serviceModel>
    <services>
      <service name="WCF_Service.WCFService">
        <endpoint address="" binding="basicHttpBinding" contract="WCF_Service.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:23456/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicTimeouts" closeTimeout="00:00:30" openTimeout="00:00:30"
          receiveTimeout="00:00:30" sendTimeout="00:00:30" />
      </basicHttpBinding>
    </bindings>
  </system.serviceModel>  

I can reach service through WcfTestClient from localhost and invoke methods offered by service. 我可以从本地主机通过WcfTestClient到达服务并调用服务提供的方法。

I can reach service through WcfTestClient from same network, however cant invoke methods offered by service. 我可以通过WcfTestClient从同一网络访问服务,但是无法调用服务提供的方法。 Once I try to invoke method I receive error message: 一旦尝试调用方法,我将收到错误消息:

There was no endpoint listening at http://localhost:23456/WCFService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.

... ...

Inner Exception:
No connection could be made because the target machine actively refused it 127.0.0.1:23456
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
   at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)

I tried to check whether there is port 23456 open and app is listening on that port through netstat -an and port 23456 is open and listening. 我试图检查是否有端口23456打开,并且应用程序正在通过netstat -an在该端口上侦听,并且端口23456已打开并正在侦听。

When I tried to modify base address (instead of localhost:23456 I put there real IP of server in network eg 10.xx.xx.xx) I was able to invoke methods as well but this is just workaround for internal solution. 当我尝试修改基址(而不是localhost:23456时,我在网络中放置了服务器的真实IP,例如10.xx.xx.xx)时,我也能够调用方法,但这只是内部解决方案的解决方法。

Server and port should be open to external network and accessbile through internet. 服务器和端口应向外部网络开放,并可以通过Internet访问。 I tried to reach service from internet and I am able to reach service from internet (proof that port is open) but facing to same issue => cant invoke methods due to issue written above. 我尝试从Internet获得服务,并且能够从Internet获得服务(证明端口已打开),但由于上述问题,面临相同的问题=>无法调用方法。

Does anyone have experience with same issue and can help me please? 有没有人遇到过同样的问题,能为我提供帮助吗?

Answered in Comments, put here for completeness. 在评论中回答,出于完整性考虑。

Check the client config points at your server correctly and not localhost. 正确检查服务器上的客户端配置点,而不是本地主机。

I'm new to WCF, but I've go the same issue latelly. 我是WCF的新手,但是最近我也遇到了同样的问题。 I've just made a config file o the client project, and a wrote there the address of the endpoint: 我刚刚在客户端项目中创建了一个配置文件,并在其中写入了端点的地址:

 <system.serviceModel>
    <services>
      <service name="WCF_Service.WCFService">
        <endpoint address="" binding="basicHttpBinding" contract="WCF_Service.IWCFService">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:23456/WCFService/" />
          </baseAddresses>
        </host>
      </service>
    </services>

You can use this reference: http://dotnetmentors.com/how-to-host-wcf-service-in-iis-7.aspx 您可以使用以下参考: http : //dotnetmentors.com/how-to-host-wcf-service-in-iis-7.aspx

From my point o view is very in handy. 在我看来,观点非常有用。 If it not works, try to recreate the project. 如果不起作用,请尝试重新创建项目。

Sounds like you are binding to the wrong IP address try this: 听起来您绑定到错误的IP地址,请尝试以下操作:

    <host>
      <baseAddresses>
        <add baseAddress="http://0.0.0.0:23456/WCFService/" />
      </baseAddresses>
    </host>

Using 0.0.0.0 instead of localhost will bind your service to all IPs on that host machine. 使用0.0.0.0代替localhost会将您的服务绑定到该主机上的所有IP。

Thanks to all for support. 感谢大家的支持。

Solution for my issue: 我的问题的解决方案:

Dont use WcfTestClient to test service from external network, at least in my case I faced issues described in my question. 不要使用WcfTestClient从外部网络测试服务,至少就我而言,我遇到了问题中所述的问题。

For beginners simple advice when you have service hosted out of IIS 当您将服务托管在IIS之外时,为初学者提供简单的建议

  1. Use config file to define WCF settings in your project (eg WCF Service Library) 使用配置文件在项目中定义WCF设置(例如WCF服务库)
  2. Dont forget to copy setting from your WCF service project to Host application into app.config 不要忘记将设置从WCF服务项目复制到Host应用程序到app.config
  3. When test from external network, use simple client app with own app.config, where endpoint has to lead to target service. 从外部网络进行测试时,请使用具有自己的app.config的简单客户端应用程序,其中端点必须引导到目标服务。

M. M.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 WCF尝试公开nettcp端点; TCP错误代码10061:无法建立连接,因为目标计算机主动拒绝它 - WCF trying to expose a nettcp endpoint; TCP error code 10061: No connection could be made because the target machine actively refused it SignalR错误“由于目标机器主动拒绝连接,因此无法建立连接” - SignalR Error “No connection could be made because the target machine actively refused it” 无法建立连接,因为目标计算机主动拒绝了它216.58.212.106:443 - No connection could be made because the target machine actively refused it 216.58.212.106:443 '由于目标机器主动拒绝它,因此无法建立连接 - 'No connection could be made because the target machine actively refused it 由于目标计算机主动拒绝连接,因此无法建立连接-客户端 - No connection could be made because the target machine actively refused it - client side 无法建立连接,因为目标计算机主动拒绝了127.0.0.1:8000 - No connection could be made because the target machine actively refused it 127.0.0.1:8000 由于目标计算机主动拒绝连接,因此无法建立连接-套接字程序 - No connection could be made because the target machine actively refused it - Socket Program 没有连接,因为目标机器主动拒绝它为什么? - No connection could be made because the target machine actively refused it why? “无法建立连接,因为目标机器主动拒绝它” Nethereum 异常 - “No connection could be made because the target machine actively refused it” Nethereum exception “无法建立连接,因为目标计算机主动拒绝了它” - “No connection could be made because the target machine actively refused it”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM