WCF Error: Could not find default endpoint element that references contract

on Feb 20, 2018 11:02 PM

Client side Code 1. I have created web application and added service reference to the Client Project 2. I tried creating a client Object like this -

Service1Client a = new Service1Client();

but getting an error message :- Could not find default endpoint element that references contract 'ServiceReference_test.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.

Could you please let me know what mistake am doing, I am new to WCF please help me

===============WCF service which returns JSON Format ===============

namespace WcfService1
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1

        public string GetData(string Id)
            return ("You entered: " + Id);


namespace WcfService1
    public interface IService1
    [WebInvoke(Method = "GET", UriTemplate = "/GetData/{Id}",
     RequestFormat = WebMessageFormat.Json,
     ResponseFormat = WebMessageFormat.Json,
     BodyStyle = WebMessageBodyStyle.Wrapped
        string GetData(string Id);

        // TODO: Add your service operations here

====================Web.Config file =========
      <service name="WcfService1.Service1" behaviorConfiguration="ServiceBehaviour">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="WcfService1.IService1"/>
        <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"/>
        <behavior name="web">
          <webHttp helpEnabled="true" automaticFormatSelectionEnabled="false"  />
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        <add binding="basicHttpsBinding" scheme="https" />
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />


Download FREE API for Word, Excel and PDF in ASP.Net: Download