Client endpoint configuration '*' was not found in 1 Endpoints, WCF, Mono

Sebastian picture Sebastian · Jun 7, 2012 · Viewed 9.6k times · Source

Hej guys,

i'm trying to access a webservice hosted on a virtual machine (Windows 7) from my Ubuntu Host using Mono.

I can import the wdsl file and generate the service reference. I copied the App.config from an other working client accessing the webservice correctly.

When i try to connect to the webservice using using System;

namespace MonoTest
{
class MainClass
{
    public static void Main (string[] args)
    {
        Console.WriteLine ("Hello World!");
        TestServer.Service1Client client = new TestServer.Service1Client("Test");
        Console.WriteLine(client.GetData(12));
        Console.ReadLine();
    }
}
}

I get an error:

System.InvalidOperationException: Client endpoint configuration 'Test' was not found in 1 endpoints.
  at System.ServiceModel.ChannelFactory.ApplyConfiguration (System.String endpointConfig) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ChannelFactory.InitializeEndpoint (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ChannelFactory`1[MonoTest.TestServer.IService1]..ctor (System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ClientBase`1[MonoTest.TestServer.IService1].Initialize (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName, System.ServiceModel.EndpointAddress remoteAddress) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ClientBase`1[MonoTest.TestServer.IService1]..ctor (System.ServiceModel.InstanceContext instance, System.String endpointConfigurationName) [0x00000] in <filename unknown>:0 
  at System.ServiceModel.ClientBase`1[MonoTest.TestServer.IService1]..ctor (System.String endpointConfigurationName) [0x00000] in <filename unknown>:0 
  at MonoTest.TestServer.Service1Client..ctor (System.String endpointConfigurationName) [0x00000] in <filename unknown>:0 
  at MonoTest.MainClass.Main (System.String[] args) [0x0000a] in /home/***/WebserviceTest/MonoTest/MonoTest/Main.cs:11 

My App.config file looks like the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <wsHttpBinding>
                <binding name="WSHttpBinding_IService1" />
            </wsHttpBinding>
        </bindings>
        <client>
            <endpoint name="Test"
                address="http://192.168.178.34:8732/Design_Time_Addresses/TestServer/Service1/"
                binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
                contract="ServiceReference1.IService1" >
                <identity>
                    <dns value="localhost" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>

Has anyone made this working using Linux?

Answer

Martin Baulig picture Martin Baulig · Nov 27, 2012

Mono's WSDL import tool does not support automatic configuration generation yet, you need to manually configure your endpoints in your app.config.

The error that you're seeing here means that WCF can't find the endpoint configuration section.

The detailed, technical reason for the problem

You are getting this because Visual Studio and Mono have a different, incompatible way of referencing the configuration section.

When adding a Service Reference in Visual Studio, it automatically creates and updates the corresponding entries in your app.config. The "contract name" that's in the generated <endpoint ... contract="contract name"> is not necessarily the fully qualified name of the data contract class in the generated Reference.cs.

Instead, Visual Studio emits

    [ServiceContractAttribute(ConfigurationName="contract name")]
    public interface YourContract {
            ....
    }

The ConfigurationName is the same as in the <endpoint ... contract="..."> element, that's how WCF finds the endpoint configuration.

In Mono, since we don't support config file generation yet, we emit

    [ServiceContractAttribute]
    public interface YourContract {
            ....
    }

Without the ConfigurationName argument, the default is the fully qualified name of that interface.

How to fix your problem

To get this to work, you need to edit your app.config file and use the fully qualified name of your service contract interface in the <endpoint ... contract="..."> element.

In your case, changing contract="ServiceReference1.IService1" into contract="TestServer.IService1" should do it.

Otherwise, look into the generated Reference.cs, search for an interface with a [ServiceContractAttribute] and which C# namespace it is in.