从另一台机器使用 WCF 自托管服务 [英] Consuming WCF self-hosted service from another machine

查看:17
本文介绍了从另一台机器使用 WCF 自托管服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've developed a self-hosted WCF service using basicHttpBinding, and all works fine when the client is on the local machine. But when I try and connect from any machine on the network, it just times out, giving me the following error:

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.

我假设我遗漏了一些基本的(毫无疑问是非常明显的)问题,我会非常向我指出它.

I'm assuming that I'm missing some fundamental (and no doubt embarassingly obvious) issue, and I'll be very grateful to have it pointed out to me.

以下是一个示例程序 + app.config,它说明了我在真实系统中遇到的相同行为,即它在本地运行良好,但是当我尝试连接时(到 http://192.168.0.59:8888/DannyService?wsdlhttp://192.168.0.59:8888/DannyService) 来自任何其他机器,它会超时.

Following is an example program + app.config that illustrates the same behaviour that I'm experiencing with the real system, i.e. it works perfectly well locally, but when I try to connect (to http://192.168.0.59:8888/DannyService?wsdl or to http://192.168.0.59:8888/DannyService) from any other machine, it times out.

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 端口)添加例外规则

Have you made sure that you don't have the firewall service running and blocking those requests? You might need to specifically add an exception rule for your custom host application (or tcp port)

这篇关于从另一台机器使用 WCF 自托管服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆