Could not find endpoint element with name and contract
Asked Answered
C

2

6

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?

Candor answered 16/1, 2013 at 22:55 Comment(2)
The address for the ABCServiceV2 has a '20' added to the end... I'm not sure if that has anything to do with it or not. Just an observation.Michaelis
I think that should be fine as the '20' is needed to make the endpoint different. Both endpoints of the service work fine on a tool like SoapUI. So the issue is somewhere in the client code.Candor
L
3

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");
Ladylike answered 16/1, 2013 at 23:33 Comment(1)
Thanks.. the issue was that i was using ServiceClient instead of Service1Client. The following code works without issues: ABCService.Service1Client ABCClient1 = new Service1Client("ABCServiceV2");Candor
F
3

Even though this post is old and answered, the answer didn't help in my case. My problem was I generated the service client with the svcutil.exe tool, but didn't specify any namespace at all; and so the contract namespace name was generated as the target namespace of the schema document by default, yes total mess.

On the other hand I was trying to use the config file generated when a service reference is added to the project. The contract namespace in this file is ServiceReference1 (by default) or any other name you want, perfect storm! But all I had to do was to remove the namespace part from the FQN from the <endpoint>'s contract attribute, and the contract became visible to the CLR.

Hope this help others

Forman answered 15/7, 2017 at 5:22 Comment(2)
This is old, but this helped a lot. Was exactly my issue. Just used the name of the interface in the contract attribute, without namespace, and it worked....Chariot
Where did you fix it, and how much of the namespace did you have to remove?Tui

© 2022 - 2024 — McMap. All rights reserved.