Wcf Service won't start if WsDiscovery Proxy service is unavailable RRS feed

  • Question

  • I have built a WsDiscovery prototype based on this sample: http://msdn.microsoft.com/en-us/library/dd456796.aspx.

    I have it all working. I can start the Ws_DiscoveryProxy, then the CalculatorServiceExe and then the DiscoveryClientApp.
    The client app finds the Calculator Service and calls the calculator methods.

    But if I just try starting the CalculatorServiceExe, I get this exception:

    Could not connect to net.tcp://localhost:9021/Announcement. The connection attempt lasted for a time span of 00:00:01.2962027.
    TCP error code 10061: No connection could be made because the target machine actively refused it

    Does that mean that if a WCF service adds an Announcement Endpoint that references a WsDiscovery proxy service that is unavailable, the WCF Service (ServiceHost) can not be started?

    Is there any way of just having the new service skip the announcement notification and continue starting. That would seem preferable than faulting the ServiceHost and not starting the WCF service at all.

    Monday, February 21, 2011 8:03 PM


  • When you add an AnnouncementEndpoint to the ServiceDiscoveryBehavior WCF automatically sends announcement messages. When the discovery proxy is not online, the result is the same as attempting to call a service that is not running, an EndpointNotFoundException.  There is a class called AnnouncementClient that allows you to manually send announcement messages. You can attempt to send the announcement message and catch the EndpointNotFoundException. Here's a quick code snippet illustrating how to use the AnnouncementClient:

        AnnouncementClient announceClient = new AnnouncementClient(announcementEndpoint);
       EndpointDiscoveryMetadata edm = new EndpointDiscoveryMetadata();
        edm.Address = new EndpointAddress(baseAddress);
        edm.ContractTypeNames.Add(new XmlQualifiedName("ICalculator"));
    catch (EndpointNotFoundException e)
      Console.WriteLine("Discovery Proxy Not Running, skipping announcement");

    If you use the announcement client make sure to not add the announcement endpoint to the ServiceDiscoveryBehavior. Please let me know if you have further questions.


    Michael Green
    WCF Documentation Team

    • Marked as answer by Yi-Lun Luo Monday, February 28, 2011 9:40 AM
    Tuesday, February 22, 2011 7:04 PM