wcfservicewmiintranet

Connect to a WCF service without endpoint address


When Clients call WCF Service, the first step is to create a connection to service (using endpoint address, or use config file to record the server url). But if client don't know the address of service, how should client find the service?


Solution

  • As I ever said, WCF server should expose the fixed endpoint to the client so that it could be discovered by the client. the DiscoveryEndpoint could use Unicast/Multicast to publish the service metadata. Unicast config the endpoint with DiscoveryEndpoint and should be assigned a fixed address, while the Multicast uses the UdpDiscoveryEndpoint which publish the service metadata with UDP Multicast. So there is no need to assign an address to UdpDiscoveryEndpoint since the fact that it has the default broadcast address, for example, ipv4 is soap.udp://239.255.255.250:3702.

    Service should add the ServiceDiscoveryBehavior to the Service behavior collection. By default after the service applies ServiceDiscovery Behavior, all of the service endpoints are exposed to clients, if we want to hide one, we need to Disable the EndpointDiscoveryBehavior on the specific endpoint.

     <endpointBehaviors>
            <behavior>
              <endpointDiscovery enabled="false">
              </endpointDiscovery>
            </behavior>
          </endpointBehaviors>
    

    On the client-side. we find the available service with DiscoveryClient class which located in System.ServiceModel.Discovery assembly. After the search completed, all the available endpoints are stored in the FindResponse object. We could invoke the target service with its Endpoints attribute.