Search code examples
c#wpfwcfwcf-rest

WCf REST service client side config file empty


I have a REST service and I have added it's reference in my WPF application. But as soon as I create a client of my proxy, it throws error and it throws error because my client side app.config is empty:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
</configuration>

This line on client throws error:

 HelloWorldClient client = new HelloWorldClient();

This is my system.servicemodel section of web.config on the server side:

 <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
    <services>
      <service name="WCFRestExample.HelloWorld">
        <endpoint address="" binding="webHttpBinding" contract="WCFRestExample.IHelloWorld"/>        
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />

        </behavior>

      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

Can anybody tell me why is app.config empty? I have also restarted VS2010 but no luck.

NOTE: When I directly browse it in the browser the service is working. So, there is no problem with server side service.

Thanks in advance :)


Solution

  • As some other posts mentioned (such as After creating a wcf service how do I tell whether its restful or soap from the wsdl? and Create a WCF Proxy for a Rest Web Service, among others), Add Service Reference does not work for REST endpoints. You'll need to create the client yourself.

    Another issue in your web.config: in order to create a REST endpoint, you need both to have the webHttpBinding (which you do) and add a <webHttp/> endpoint behavior to your endpoint (which you don't).