从另一台机器使用WCF自托管服务

我使用basicHttpBinding开发了一个自托管的WCF服务,当客户端在本地机器上时,一切正常.但是当我尝试从网络上的任何机器连接时,它只是超时,给我以下错误:

There was an error downloading 'http://192.168.0.59:8888/DannyService?wsdl'.
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.59:8888
Metadata contains a reference that cannot be resolved: 'http://192.168.0.59:8888/DannyService?wsdl'.
Could not connect to http://192.168.0.59:8888/DannyService?wsdl. TCP error code 10060:     A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.59:8888. 
Unable to connect to the remote server
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.0.59:8888
If the service is defined in the current solution, try building the solution and adding the service reference again.

我假设我错过了一些基本的(毫无疑问是非常明显的)问题,我将非常感谢它向我指出.

下面是一个示例程序app.config,它说明了我在实际系统中遇到的相同行为,即它在本地运行得非常好,但是当我尝试从任何其他机器连接(到http://192.168.0.59:8888/DannyService?wsdlhttp://192.168.0.59:8888/DannyService)时,它的次数出.

namespace DannyService
{
    using System;
    using System.Reflection;
    using System.ServiceModel;

    [ServiceContract]
    interface IDannyControl
    {
        [OperationContract]
        string SayHi();
    }

    class DannyControl
        : IDannyControl
    {
        public string SayHi()
        {
            return "Hi!";
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(DannyControl));

            host.Open();

            Console.ReadLine();

            host.Close();
        }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="DannyServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <services>
      <service name="DannyService.DannyControl" behaviorConfiguration="DannyServiceBehaviour">
        <host>
          <baseAddresses>
            <add baseAddress="http://192.168.0.59:8888/DannyService"/>
          </baseAddresses>
        </host>
        <endpoint address="danny" binding="basicHttpBinding" contract="DannyService.IDannyControl" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

提前谢谢了.

最佳答案 您是否确定没有运行防火墙服务并阻止这些请求?您可能需要为自定义主机应用程序(或tcp端口)专门添加例外规则

点赞