Take the 2-minute tour ×

I am trying to add a WCF service reference to my web application using VS2010. It seems to add OK, but the web.config is not updated, meaning I get a runtime exception:

Could not find default endpoint element that references contract 'CoolService.CoolService' 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.

Obviously, because the service is not defined in my web.config. Steps to reproduce:

  1. Right click solution > Add > New Project > ASP.NET Empty Web Application.
  2. Right click Service References in the new web app > Add Service Reference.
  3. Enter address of my service and click Go. My service is visible in the left-hand Services section, and I can see all its operations.
  4. Type a namespace for my service.
  5. Click OK. The service reference is generated correctly, and I can open the Reference.cs file, and it all looks OK.
  6. Open the web.config file. It is still empty!

        <bindings />
        <client />

Why is this happening? It also happens with a console application, or any other project type I try. Any help?

Here is the app.config from my WCF service:

<?xml version="1.0"?>


    <compilation debug="true" />


      <service name="CoolSQL.Server.WCF.CoolService">

        <endpoint address=""
            <dns value="localhost" />

        <endpoint address="mex"
          contract="IMetadataExchange" />

            <add baseAddress="http://localhost:8732/Design_Time_Addresses/CoolSQL.Server.WCF/CoolService/" />



        <behavior name="webBehavior">
          <webHttp />
        <behavior name="SilverlightFaultBehavior">
          <silverlightFaults />
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />


        <binding name="DefaultBinding"
          <readerQuotas maxArrayLength="2147483647"
            maxStringContentLength="2147483647" />


        <add name="silverlightFaults"
          type="CoolSQL.Server.WCF.SilverlightFaultBehavior, CoolSQL.Server.WCF" />

      <messageLogging logEntireMessage="true"
        maxSizeOfMessageToLog="2000" />


    <supportedRuntime version="v4.0"
      sku=".NETFramework,Version=v4.0" />

      <source name="System.ServiceModel.MessageLogging"
        switchValue="Information, ActivityTracing">
          <add name="messages"
            initializeData="c:\messages.e2e" />

share|improve this question

1 Answer 1

I discovered how to work around this. My WCF service was implemented in its own project, and hosted in by a separate console application in the same solution. If I run the WCF service as the solution's startup project (eg. let VS host it for me) then adding the reference works fine and the correct lines are added to the client web.config. But if I host service from within my console application, while I can still add the reference, the client's web.config does not get modified. So, a workaround is to first let VS host the service, then add the reference, then change the service to be hosted (at the same address and port) in the console application.

This is surprising behaviour, and I am curious if anyone can shed any light on it?

share|improve this answer
Is your server-side configuration in the console app and the WCF service project? –  Kirk Broadhurst Jan 7 '11 at 3:09
Nope, just in the WCF service project. –  Mike Chamberlain Jan 7 '11 at 4:05

Your Answer


