C# – Service can’t find endpoint of other service in WCF

ciisservicewcf

I am trying to create two WCF services which should be able to access each other. However I am getting this error message:
The server encountered an error processing the request. The exception message is 'Could not find default endpoint element that references contract 'AddonWCFService.IService1' 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.'.

I call the Test() Method from this service

namespace CustomersService
{
    [ServiceContract]
    public interface ICustomers
    {
        [OperationContract] 
        [WebGet]
        string Test();
    }

    public class Customers : ICustomers
    {
        private int m_i = 0;

        public int GetCounter()
        {
            return m_i;
        }

        public void Test()
        {
            AddonWCFService.Service1Client foo = new AddonWCFService.Service1Client();
        }
    }
}

The other service

namespace AddonWCFWebservice
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        void Init();
    }


    public class Service1 : IService1
    {
        public void Init()
        {

        }
    }
}

My webconfig:

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <services>

            <service behaviorConfiguration="MyserviceBehavior" name="CustomersService.Customers">
                <endpoint name="ws" address="ws" binding="wsHttpBinding" contract="CustomersService.ICustomers"/>
                <endpoint name=""
                          address="" 
                          binding="webHttpBinding" 
                          contract="CustomersService.ICustomers" 
                          behaviorConfiguration="WebBehavior"/>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
            <service name="AddonWCFWebservice.Service1" behaviorConfiguration="MyserviceBehavior">
                <endpoint address="" binding="wsHttpBinding" contract="AddonWCFWebservice.IService1"/>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyserviceBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="WebBehavior">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
    <system.web>
        <compilation debug="true"/>        
        <customErrors mode="Off"/>
    </system.web>
</configuration>

Both services reside in the same active directory of IIS . I added the service reference to the VS C# projects using the web URL i.e. http://www.foobar.baz/Test/Service1.svc and http://www.foobar.baz/Test/Customers.svc

It's probably something obvious but I'm fairly new to the whole WCF business. Thanks!

Update: The solution was to add a client section to my webconfig. Also I used basicHttpBinding over wsHttpBinding because my security will be incorparated elsewhere because it is a public service. I had to match the binding of the client to the binding of the service section: both basicHttpBinding

<?xml version="1.0"?>
<configuration>
    <system.serviceModel>
        <client>
          <endpoint
            name=""
            address="http://demo.mydomain.baz/TestService/Service1.svc"
            binding="basicHttpBinding"
            contract="AddonWCFService.IService1" />
        </client>

        <services>
            <service behaviorConfiguration="MyserviceBehavior" name="CustomersService.Customers">
                <endpoint name="ws" address="ws" binding="wsHttpBinding" contract="CustomersService.ICustomers"/>
                <endpoint name=""
                          address="" 
                          binding="webHttpBinding" 
                          contract="CustomersService.ICustomers" 
                          behaviorConfiguration="WebBehavior"/>
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>
            <service name="AddonWCFWebservice.Service1" behaviorConfiguration="MyserviceBehavior">
                <endpoint address="" binding="basicHttpBinding" contract="AddonWCFWebservice.IService1"/>
                <!--
                <endpoint address="" 
                          binding="webHttpBinding" 
                          contract="AddonWCFWebservice.IService1"
                          behaviorConfiguration="WebBehavior"/>
                -->
                <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
            </service>


        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="MyserviceBehavior">
                    <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
                    <serviceMetadata httpGetEnabled="true"/>
                    <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="WebBehavior">
                    <webHttp />
                </behavior>
            </endpointBehaviors>
        </behaviors>
    </system.serviceModel>
    <system.web>
        <compilation debug="true"/>        
        <customErrors mode="Off"/>
    </system.web>
</configuration>

Best Answer

The problem with your config is that you have no client configurations. You have only server parts. You need to have client element with endpoints. Take a look here: http://msdn.microsoft.com/en-us/library/ms731745.aspx

If you are not so sure about you config skills I would advise you to open your config with SvcConfigEditor.exe. You will immediately see what's configured. You can find it here: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\SvcConfigEditor.exe. If you will do it - you will see that there are no clients configured

Related Topic