2

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 :)

Jaggu
  • 6,298
  • 16
  • 58
  • 96
  • When you create the ServiceReference, check the visual studio output window for warnings & errors. Even if you may not see something in the errorlist, check the output window, do you see anything? – Dominik Jul 26 '11 at 12:59
  • @Dominik: No! Nothing at all. – Jaggu Jul 26 '11 at 13:01
  • Did you came across http://stackoverflow.com/questions/2159107/visual-studio-does-not-generate-app-config-content-when-add-service-reference ? – Dominik Jul 26 '11 at 13:11

1 Answers1

4

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).

Community
  • 1
  • 1
carlosfigueira
  • 85,035
  • 14
  • 131
  • 171
  • Thanks for your help but can you tell what do you mean by 'create the client yourself'. Can you point me to some example? Or if you have it can you show it? – Jaggu Jul 27 '11 at 03:44
  • Also where should I write . No matter wherever I write I get a redline in web.config meaning it is not able to recognize the element. – Jaggu Jul 27 '11 at 03:48
  • For "creating the client yourself": if you can share the same [ServiceContract] interface between the client and the server, you can use the WebChannelFactory (and the constructor which takes a single Uri parameter) to create a proxy to talk to the service. – carlosfigueira Jul 27 '11 at 04:35
  • The element must be inside one element. – carlosfigueira Jul 27 '11 at 04:36
  • There is HttpClient class available in REST starter kit 2. Can I use that? – Jaggu Jul 27 '11 at 07:01
  • If you want to use the HttpClient class, I'd suggest you to use the one which is on the WCF Web APIs from http://wcf.codeplex.com - it's the same class really, but it's more recent and may have some bug fixes. – carlosfigueira Jul 27 '11 at 13:57