C# – WCF Error – Could not find default endpoint element that references contract ‘UserService.UserService’


Any ideas how to fix this?

UserService.UserServiceClient userServiceClient = new UserServiceClient();
            userServiceClient.GetUsersCompleted += new EventHandler<GetUsersCompletedEventArgs>(userServiceClient_GetUsersCompleted);


            <binding name="BasicHttpBinding_UserService" 
                <security mode="None" />
        <endpoint address="http://localhost:52185/UserService.svc" 
                  name="BasicHttpBinding_UserService" />
            <behavior name="Shell.Silverlight.Web.Service3Behavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="false" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
        <service behaviorConfiguration="Shell.Silverlight.Web.Service3Behavior" 
            <endpoint address="" 
                      contract="Shell.Silverlight.Web.Service3" />
            <endpoint address="mex" 
                      contract="IMetadataExchange" />

Could not find default endpoint element that references contract 'UserService.UserService' 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 didn't mention that this was a Silverlight application. I had the wcf reference in a DLL which had it's own "ServiceReferences.ClientConfig" file. I moved the contents of the DLL's ServiceReferences.ClientConfig to the main silverlight project and it worked.

Best Solution

I had a run in with the same problem. My application was also a Silverlight application and the service was being called from a class library with a custom UserControl that was being used in it.

The solution is simple. Copy the endpoint definitions from the config file (e.g. ServiceReferences.ClientConfig) of the class library to the config file of the silverlight application. I know you'd expect it to work without having to do this, but apparently someone in Redmond had a vacation that day.

Related Question