0

I have Client/Server application that uses service discovery:

Server:

using (ServiceHost host = new ServiceHost(Instance, baseAddress))
{
    try
    {
         host.Description.Behaviors.Add(new ServiceDiscoveryBehavior());
         host.AddServiceEndpoint(new UdpDiscoveryEndpoint());
         ...

         host.Open();
         while (!Program.IsExit && !cancel)
         {
             Thread.Sleep(50);
         }
         host.Close();
     }
     catch (Exception ex)
     {
         ....
     }

Discovering service:

DiscoveryClient discoveryClient = new DiscoveryClient(new UdpDiscoveryEndpoint());
var services = discoveryClient.Find(new FindCriteria(typeof(IUpdateServerService)));
discoveryClient.Close();

On local machine this works fine. Service is found. On the other hand when someone runs client on other machine service seem not to be found (Client should register itself on Server but it does not).

What can be wrong? My thirst thought is that UDP traffic can be blocked by firewall. How can I change that not to use UDP? All clients and Server are in the same domain.

Pablo notPicasso
  • 3,031
  • 3
  • 17
  • 22

1 Answers1

0

This sort of issue substantially due to the firewall issue, we have to add a firewall rule to permit the ALL UDP traffic.
Allowing WCF udpDiscoveryEndpoint though firewall
WCF Discovery simply doesn't work
Microsoft document.
https://web.archive.org/web/20161111140652/https://msdn.microsoft.com/en-us/library/dd352335.aspx
We can also discover the client by using the HTTP protocol. Here is an example.
Server-side.

<system.serviceModel>
    <services>
      <service name="ConsoleApp4.Service1">
        <endpoint address=""
                  binding="wsHttpBinding" contract="ConsoleApp4.IService1"/>
        <endpoint kind="discoveryEndpoint" address="http://localhost:1000/dis" binding="wsHttpBinding" bindingConfiguration=""></endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://vabqia969vm:22000"/>
          </baseAddresses>
        </host>
      </service>
    </services>
   <bindings>
     <wsHttpBinding>
       <binding>
         <security mode="None"></security>
       </binding>
     </wsHttpBinding>
   </bindings>
   <behaviors>
     <serviceBehaviors>
       <behavior>
         <serviceDiscovery></serviceDiscovery>
       </behavior>
     </serviceBehaviors>
   </behaviors>
  </system.serviceModel>

Client-side. Configuration.

    <system.serviceModel>
      <client>
        <endpoint name="dis_client" kind="discoveryEndpoint" address="http://vabqia969vm:1000/dis" binding="wsHttpBinding"></endpoint>
      </client>
    <bindings>
      <wsHttpBinding>
        <binding>
          <security mode="None"></security>
        </binding>
      </wsHttpBinding>
    </bindings>
</system.serviceModel>

Code.

DiscoveryClient client = new DiscoveryClient("dis_client");
FindResponse response = client.Find(new FindCriteria(typeof(IService1)));
foreach (EndpointDiscoveryMetadata item in response.Endpoints)
{
    WSHttpBinding binding = new WSHttpBinding();
    binding.Security.Mode = SecurityMode.None;
    ChannelFactory<IService1> factory = new ChannelFactory<IService1>(binding, new EndpointAddress(item.Address.Uri));
    var service = factory.CreateChannel();
    var result = service.GetData(34);
    Console.WriteLine(result);
}

Feel free to let me know if there is anything I can help with.

Abraham Qian
  • 7,117
  • 1
  • 8
  • 22