WCF Error - Could not find endpoint element with name and contract in the ServiceModel client configuration section

This week I had to work on an old Silverlight and WCF application. So I had to make this Silverlight 3.0 application consume a WCF service that is used to perform search in Amazon.com database. This post is about first WCF error I ran into when my silverlight application tried to call into my WCF web service. And I realized this is a very common issue lot of developers run into when developing a Silverlight application that consumes WCF service.

{System.InvalidOperationException: Could not find endpoint element with name 
'BasicEndPoint' and contract 'ProductSearchService.IAmazonSearchService' 
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....

The error provided me some starting point to start my diagnosis. Here are the steps that i followed and approached the solution.

Check WCF Configuration File On Client

When you choose Add Service Reference option in Visual Studio to add a WCF service reference to your Silverlight application, it will add a WCF client configuration file ServiceReferences.ClientConfig in your project. Open that file to check if it does have correct WCF configuration entries. Well, in my case, for some reason Visual Studio choked and added an empty ServiceReferences.ClientConfig file. So I manually added the configuration entried to create a WCF proxy.

        <binding name="BasicEndPoint" maxBufferSize="2147483647" 
          <security mode="None" />
        <binding name="BasicHttpBinding_IAmazonSearchService" 
          <security mode="None" />
      <endpoint address="http://localhost/ProductsSearch/AmazonSearchService.svc"
        name="BasicHttpBinding_IAmazonSearchService" />

After populating configuration, I still kept getting the same when my Silverlight application tried to connect to WCF service. So I moved to next end point of this equation that was server side WCF service.

Silverlight Supports basicHttpBinding and not wsHttpBinding

I quickly checked the service implementation code and did not find anything wrong. There was nothing to check much because my one method in service was returning statically constructed list. So at this point I did not have to worry about diagnosing any issues with Amazon.com web service itself.

Now I opened web.config file to look for configuration entries for my WCF configuration. Oh well, there was something obviously wrong. Notice binding value in endpoint configuration. It is set to wsHttpBinding

    <behavior name="ProductsSearch.AmazonSearchServiceBehavior">
     <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    <service behaviorConfiguration="ProductsSearch.AmazonSearchServiceBehavior" 
      <endpoint address="" binding="wsHttpBinding" 
         <dns value="localhost"/>
      <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

Change the endpoint configuration to use basicHttpBinding. Recompile the service and go back to Silverlight project. Right click on the service reference and choose the option to update it. And now compile Silverlight project.

It worked!

Yes, that did work. So if you are working with a Silverlight 3.0 application that is going to consume a WCF service, make sure that:

  • Your WCF service is configured to use basicHttpBinding
  • Your client side WCF configuration file has correct information about the binding etc.
  • And if you are calling the client proxy constructor by name, then you do have correct name for your endpoint in client configuration file.




19.1 °C / 66.5 °F

weather conditions Clear

Monthly Posts

Blog Tags