0

I am adding a WCF client via “Add Service Reference” to the Class project with Visual Studio 2012. However I am getting the well known error:

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

The steps I followed was : (1) Create the Service1.cs and output.config via svcutil.exe, (2) Add service reference I am giving reference namespace as “MyFirstWcfWebServiceReference”. (3) add your existing Service1.cs file to the project. (4) in app.config Removed “MyFirstWcfWebServiceReference” and keep only IService1 in contract, (6) Build Project.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
    </configSections>
      <system.serviceModel>
        <bindings>
          <basicHttpBinding>
            <binding name="WCFServiceBinding" />
          </basicHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://localhost/webiste/WebService.svc"
            binding="basicHttpBinding" bindingConfiguration="WCFServiceBinding"
            contract="IService1" name="WCFServiceBinding" />
        </client>
      </system.serviceModel>
</configuration>
Jim
  • 2,760
  • 8
  • 42
  • 66
  • 1. Why are you using svcutil and add service reference? That's like using add service reference twice for the same service - pick one and use it (actually, I believe add service reference calls svcutil internally). 2. Do you mean you're adding a service to your project? Clients **use** add service reference - you don't "add" a client to a service. 3. Contract in the config should be fully qualified (`Service1.IService1`, not `IService1`). 4. Can you post your service's config file? – Tim Sep 18 '13 at 13:38
  • Thanks for the response, Acutally i did follow this tutorial http://a1ashiish-csharp.blogspot.com/2012/01/cnet-how-to-consume-wcf-web-service-in.html which describes the above procedure. Is this correct? – Jim Sep 19 '13 at 03:12
  • 1
    The procedure that author recommends does not make sense to me. Normally, you'd use either svcutil or Add Service Reference, not both. Add Service Reference will create the proxy for you to use, plus any applicable data contracts that may have been defined (the same things the output cs file will contain from svcutil). There are some difference between the way Add Service Reference works and scvutil, but either one is perfectly fine, especially if you're just starting out. I don't use either (I create all my clients with `ChannelFactory`, but that's different story). – Tim Sep 19 '13 at 04:28
  • Thanks, Actually I was wondering the same thing ... So I've created new Winform project and followed http://msdn.microsoft.com/en-us/library/bb386386.aspx plus http://a1ashiish-csharp.blogspot.com/2012/01/cnet-how-to-consume-web-service-in-cnet.html and suddenly it start working ... will test on Class project also – Jim Sep 19 '13 at 04:59

0 Answers0