Search code examples
c#.netwcfwcf-bindingwcf-client

WCF - Client Endpoint Configuration Error


In my client application, I'm getting the following error:

Could not find endpoint element with name 'QueuedService' and contract
'IMyService' 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.

I used svutil.exe to generate the client proxy I'm using. Typically I hand-roll my own proxy, and I notice the generated version of the interface for the service contract was not in the namespace I originally specified in the service contract:

// Auto-generated proxy

namespace MyServices.Contracts
{
    // Request object in correct namespace

    [System.Runtime.Serialization.DataContractAttribute(
        Name="MyRequest",
        Namespace="http://schemas.datacontract.org/2004/07/MyServices.Contracts")]
    public class MyRequest
    {
        // ...
    }
}

// Service contract NOT in namespace

[System.ServiceModel.ServiceContractAttribute(
    ConfigurationName="IMyService")]
public interface IMyService
{
    // ...
}

My host application web.config specifies the service endpoints (one for MSMQ and one for TCP):

<system.serviceModel>
<service>

<!-- etc... -->    

<endpoint name="QueuedService"
          address="net.msmq://localhost/private/MyQueue"
          binding="netMsmqBinding"
          bindingConfiguration="MsmqDefaultBinding_Local"
          contract="MyService.Contracts.IMyService" />
<endpoint name="TcpService"
          address="net.tcp://localhost/ServiceHost/TheService.svc"
          contract="MyServices.Contracts.IMyService"
          binding="netTcpBinding"
          bindingConfiguration="netTcpWindowsBinding" />
</service>
</system.serviceModel>

The client app is using the service like this:

var endpointConfigName = GetEndpointConfigNameFromConfig();

using(var myServiceClient = new MyServiceClient(endpointConfigName))
{
    // Create Request object...

    // Call service like so:

    myServiceClient.SomeServiceMethod(requestObject);
}

And the client's web.config:

<client>
    <endpoint name="QueuedService"
            address="net.msmq://localhost/private/MyQueue"
            binding="netMsmqBinding"
            bindingConfiguration="MsmqDefaultBinding_Local"
            contract="MyServices.Contracts.IMyService" />
    <endpoint name="TcpService"
            address="net.tcp://localhost/ServiceHost/TheService.svc"
            contract="MyServices.Contracts.IMyService"
            binding="netTcpBinding"
            bindingConfiguration="netTcpWindowsBinding" />
</client>

Any ideas???


Solution

  • Seems like the ConfigurationName in the Generated proxy is just IMyService rather than MyServices.Contracts.IMyService. So in your clients web.config can you just have the contract as IMyService rather than the complete one and test if that works.