wcf自托管服务和跨机器无法正常工作的wcf发现

时间:2013-02-04 07:22:17

标签: wcf ws-discovery

我花了3个小时寻找任何样品并浏览了很多文章。我试图让WCF adhoc发现机制为自托管的Windows服务工作。如果我在同一台机器上运行客户端它可以工作,但在另一台机器上却没有。每个教程/样本(方便地)都在同一台工作的机器上显示它。

  • 我在两台机器上禁用了防火墙。
  • 如果我直接在客户端使用终点,它就可以了。因此,它只是服务发现无效。

这是我的服务器代码:

static void Main(string[] args)
    {
        Uri baseAddress = new Uri(string.Format("http://{0}:12345/discovery/Myservice/", System.Net.Dns.GetHostName()));
        Console.WriteLine(baseAddress);
        using (ServiceHost serviceHost = new ServiceHost(typeof(SampleService.Service1), baseAddress))
        {
            serviceHost.AddServiceEndpoint(typeof(SampleService.IService1), new BasicHttpBinding(), string.Empty);
            serviceHost.Description.Behaviors.Add(new ServiceDiscoveryBehavior());

            ServiceMetadataBehavior metaDataBehavior = new ServiceMetadataBehavior();
            metaDataBehavior.HttpGetEnabled = true;
            serviceHost.Description.Behaviors.Add(metaDataBehavior);

            serviceHost.AddServiceEndpoint(new UdpDiscoveryEndpoint());
            serviceHost.Open();
            Console.WriteLine("Press to terminate service.");
            Console.ReadLine();
        }
    }

这是我的客户代码:

static void InvokeService()
    {
        Console.WriteLine("\nFinding Service ..");
        DiscoveryClientBindingElement discoveryClientBindingElement =
              new DiscoveryClientBindingElement();
        var Services =
             discoveryClientBindingElement.FindCriteria = new FindCriteria(typeof(ServiceReference1.IService1));

        discoveryClientBindingElement.DiscoveryEndpointProvider = new UdpDiscoveryEndpointProvider();

        // The service uses the BasicHttpBinding, so use that and insert the DiscoveryClientBindingElement at the 
        // top of the stack
        CustomBinding binding = new CustomBinding(new BasicHttpBinding());
        binding.Elements.Insert(0, discoveryClientBindingElement);

        ServiceReference1.Service1Client client = new ServiceReference1.Service1Client(binding, DiscoveryClientBindingElement.DiscoveryEndpointAddress);
        Console.WriteLine("Data = " + client.GetData(1));
    }

非常感谢任何帮助。

0 个答案:

没有答案