0
votes

I have a WCF service Service1 that has a service reference to another WCF service Service2.

Both services are self hosted and can be accessed normally when not referencing one another.

Inside a method in Service1 I have a call to the other service

public String DoWork()
{
    using(Service2Client client = new Service2Client())
    {
         return client.DoWork();
    }
}

The method containing this code is called from another project referencing Service1 like so:

using (Service1Client client = new Service1Client())
{
     result = client.DoWork();
}

When this project attempts to consume the service I get an error message:

System.ServiceModel.FaultException`1: 'Could not find default endpoint element that references contract 'Service2Reference.IService2' 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 contract could be found in the client element.'

Any ideas on how to fix this? I am fairly inexperienced with WCF.

I have read about adding the endpoint but I'm not entirely sure which config file to add it to (e.g. the client which makes the call or the host of the service which calls another service)?

Thanks

1

1 Answers

2
votes

Add a client tag to the Service1 App.Config file. The client endpoint that is added to the Service1 App.Config file should match an exposed endpoint that is setup is Service2's App.Config file. The client tag in service one would look like this:

    <system.serviceModel>
        ....Other Config....
        <client>
            <endpoint address="serviceAddress" binding="bindingType"
             bindingConfiguration="BindingConfig" contract="ContractNamespace"
             name="NameOfEndpoint">
        </client>
     </system.serviceModel>

The binding type needs to match the binding type that is exposed by the hosted service, Service 2 in your example. Contract is the Interface that describes the methods that are exposed by the service.