0
votes

I am unable to consume the wcf restful service hosted in IIS.i.e at http://192.168.100.87:7001/ProductRESTService.svc/.

I have created a client application and added the service reference and created the proxy for service and accesing the using prxoy.

The error is:

Could not find default endpoint element that references contract 'ServiceReference2.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 web.config file of service is following.

 <system.serviceModel>
    <services>
        <service name="MyRESTService.ProductRESTService" behaviorConfiguration="serviceBehavior">
            <endpoint address=""
                      binding="webHttpBinding"
                      contract="MyRESTService.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>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

hi, please check my client configuration file.

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

  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_ICreate_Restful_WCF_Service"/>
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://192.168.1.xxx:2777/ProductRESTService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_ICreate_Restful_WCF_Service" contract="ServiceReference1.IProductRESTService" name="BasicHttpBinding_ICreate_Restful_WCF_Service"/>
    </client>
  </system.serviceModel>

</configuration>
1
Post your client config file - the one you posted is for the service. The issue appears to lie with your client, not the service.Tim
Hi, @Tim, now i provide the client configuration file,please check it once.if any errors let me know.GOPAL YADAV

1 Answers

0
votes

Why do you use client applicatin for rest service? For rest service, we could call it directly by httpWebRequest. Add Service Reference uses WSDL or ws-metadataExchange, and rest does not have metadata. If you use add service reference, it will not generate any app.config settings, and it will produce this error. If you want to try add service reference to use wcf service, you need to use soap service instead of rest service.