简体   繁体   English

使用另一台计算机上的WCF自托管服务

[英]Consuming WCF self-hosted service from another machine

I've developed a self-hosted WCF service using basicHttpBinding, and all works fine when the client is on the local machine. 我已经使用basicHttpBinding开发了一个自托管的WCF服务,并且当客户端位于本地计算机上时,它们都可以正常工作。 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. 我假设我失去了一些基本的(毫无疑问embarassingly明显的)问题,我将非常感谢有它指给我看。

Following is an example program + app.config that illustrates the same behaviour that I'm experiencing with the real system, ie 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. 以下是一个示例程序+ 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();
        }
    }
}

and

<?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>

Many thanks in advance. 提前谢谢了。

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) 您可能需要为自定义主机应用程序(或tcp端口)专门添加例外规则

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM