REST service works fine in Microsoft WCF Test Client but fails in browser

Had a  WCF Rest service.  On svc file, when you hit F5, Microsoft WCF Test Client opens up and you can invoke all the methods and everything works fine. However, when I open the same service in browser, there is no response. And the problem was default web.config does not have the following lines under system.serviceModel

  <service name="CRService.Amazon";  behaviorConfiguration="ServiceBehavior";>
IAmazon" behaviorConfiguration="web" />

    <behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
    <behavior name="web">

just so you can relate the above entries, here is my interface definition and source code.

namespace CRService
public interface IAmazon
         [WebInvoke (Method= "GET",
         ResponseFormat= WebMessageFormat.Json,
         IEnumerable GetData(string id);

public class Amazon : IAmazon
      public IEnumerable  GetData(string key)
             AmazonConnector.Amazon a = new AmazonConnector.Amazon();
             return  a.Search(key);

and now my http://localhost:61527/Amazon.svc/json/123 URI returns the nice JSON.

I must add, if you are writing a new web service, you should be using WebAPI.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s