Hassaan
Hassaan

Reputation: 3991

Could not find default endpoint element that references contract?

I am a beginner to WCF service. I create a Wcf rest service. This works fine if i browse it.

Then i added a new web application and add reference of that service. The service is loaded correctly. But when I check the web.config it doesnot contain any detail about service model and its empty. I implemented and built and run the solution, it breaks and give this error:

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

My service webconfig is as:

<system.serviceModel>
    <services>
      <service name="WcfService1.ProductRestService"
               behaviorConfiguration="serviceBehavior">
    <endpoint address="ProductRestService" binding="webHttpBinding" contract="WcfService1.IProductRESTService"
              behaviorConfiguration="web"></endpoint>
    </service>
    </services>
      <behaviors>
        <serviceBehaviors>
          <behavior name="serviceBehavior">
            <serviceMetadata httpGetEnabled="true"/>
            <serviceDebug includeExceptionDetailInFaults="false"/>
          </behavior>
        </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
      </behaviors>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true"/>

  </system.serviceModel>

and I implemeted it for testing as:

 if (!IsPostBack)
  {
       ProductRestService.ProductRESTServiceClient pro = new ProductRestService.ProductRESTServiceClient("ProductRestService");
       var prodcuts = pro.GetProductList();
       GridView1.DataSource = prodcuts;
       GridView1.DataBind();
  }

and client web.config is empty as:

<configuration>
    <system.web>
      <compilation debug="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" />
    </system.web>

</configuration>

How do I resolve this help!!!

Upvotes: 1

Views: 2081

Answers (1)

Chamika Sandamal
Chamika Sandamal

Reputation: 24302

Add Following code in your web.config file and it will fix the problem,

<system.serviceModel>
  <bindings>
    <webHttpBinding>
      <binding name="WebHttpBinding_IProductRESTService" />
    </webHttpBinding>
  </bindings>
  <client>
    <endpoint address="http://{DomainName}/ProductRestService/" binding="webHttpBinding" bindingConfiguration="WebHttpBinding_IProductRESTService" contract="WcfService1.IProductRESTService" name="WebHttpBinding_IProductRESTService" />
  </client>
</system.serviceModel>

Upvotes: 2

Related Questions