【问题标题】:Consuming WCF self-hosted service from another machine从另一台机器使用 WCF 自托管服务
【发布时间】:2016-08-23 18:56:23
【问题描述】:

我使用 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 或 http://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>

非常感谢。

【问题讨论】:

  • 你能从另一台机器上的浏览器中检索wsdl或查看svc文件吗?
  • 如果您的意思是将192.168.0.59:8888/DannyService?wsdl 放在浏览器中,或者放在“添加服务引用”对话框中,那么不会。如果有什么,那我不知道。 ;-/
  • 不。两者都只是超时。它是一个自托管服务(在 Windows 服务中)。但是我发布的示例具有完全相同的行为。试试看! ;-/
  • 一切似乎都很好 - 真是个愚蠢的问题:当您尝试连接到 Windows NT 服务时,它是否已启动并正在运行?由于它是自托管的,因此确保服务正在运行是您自己的责任......
  • ?wsdl 不与 basicHttpBinding 一起使用。只是192.168.0.59:8888/DannyService - 你试过吗?

标签: wcf web-services


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-30
    • 1970-01-01
    • 1970-01-01
    • 2011-09-04
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多