Could not find endpoint element with name and contract

ipoh picture ipoh · Jan 16, 2013 · Viewed 22.4k times · Source

I have added reference to a WCF service that has two end points. On adding the service the following get added to the Config file:

<client>
  <endpoint name="ABCServiceV1" address="http://staging.ABCwebservices.com/ABC/Service.svc"
    binding="basicHttpBinding" bindingConfiguration="ABCServiceV1"
    contract="ABCService.IService"  />
  <endpoint name="ABCServiceV2" address="http://staging.ABCwebservices.com/ABC/Service.svc/20"
    binding="basicHttpBinding" bindingConfiguration="ABCServiceV2"
    contract="ABCService.IService1"  />
</client>

The code to create the client is as as below:

ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV2");

However, I am getting an runtime error - "Could not find endpoint element with name 'ABCServiceV2' and contract 'ABCService.IService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element."

if i used ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1"); then everything works fine. But when using ABCServiceV2 it is trying to look for Contract - ABCService.IService - when it should be looking for - ABCService.IService1.

How do i make it look for the correct contract?

Answer

chrisn picture chrisn · Jan 17, 2013

If you added a second reference to a different service (ABCServiceV2) then I believe this will have generated a second service class for ABCServiceV2. The two classes will implement separate contracts (ABCService.IService and ABCService.IService1) so you won't be able to interchange the endpoints.

I believe you should be able to initialise your two service endpoints like so:

ABCService.ServiceClient ABCClient = new ServiceClient("ABCServiceV1");
ABCService.Service1Client ABCClient1 = new Service1Client("ABCServiceV2");