tags:

views:

121

answers:

1

Hello,

How do I access this WCF function through the browser and view the JSON code...

[OperationContract]
[WebInvoke(Method="POST",BodyStyle=WebMessageBodyStyle.Wrapped,ResponseFormat=WebMessageFormat.Json)]
string GetData(int value);

Here's the code in my service...its just a sample function...

  public class Service1 : IService1
    {
        public string GetData(int value)
        {
            return string.Format("You entered: {0}", value);
        }

I tried pasting this url "http://localhost:25521/Service1.svc/GetData/1" on my browser but,it doesn't seem to execute the function.How do I execute this and test it on the browser to see the JSON stuff?

Thanks

+2  A: 

I suggest using Fiddler.

Simply create a request to your URI with the "Request Builder", and make sure to add the header:

Content-type: application/json

You will get back the raw JSON.

Daniel Vassallo
I agree with using Fiddler. One additional point is that you also make sure to choose POST as the method (vs. GET).
Drew Marsh
I also had to use WebScriptServiceHostFactory to get it to work
Josh