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

时间:2009-10-29 22:51:07

标签: wcf web-services

我使用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?wsdl或{ {3}})来自任何其他机器,它会超时。

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>

非常感谢提前。

1 个答案:

答案 0 :(得分:2)

您是否确定没有运行防火墙服务并阻止这些请求?您可能需要为自定义主机应用程序(或tcp端口)

专门添加例外规则