.netwcfws-discoverywcf-discovery

WCF discovery: EndpointNotFoundException even though the endpoint was found


I'm using WS Discovery to dynamically find and connect to endpoints on the local network.

var cli = new DiscoveryClient (new UdpDiscoveryEndpoint ());
var response = cli.Find (new FindCriteria (typeof (IFoo)));

returns net.tcp://localhost:8000/, which is correct. But

var ep = new DynamicEndpoint (
    ContractDescription.GetContract (typeof (IFoo)), new NetTcpBinding ());
var cf = new ChannelFactory<IFoo> (ep);
var ch = cf.CreateChannel ();
ch.SomeMethod ();

throws an EndpointNotFoundException with this message:

"1 endpoint(s) were discovered, but the client could not create or open the channel with any of the discovered endpoints."

I googled for the error message but there were no results! What is happening, and how can I fix this?


Solution

  • At least in my case the error was due to a wrong binding - its SecurityMode was not set correctly.