Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1088319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:03:23+00:00 2026-05-16T23:03:23+00:00

I am trying to make my WCF service method to return JSON-object, but it

  • 0

I am trying to make my WCF service method to return JSON-object, but it doesn’t work, when I open in a web browser it shows xml.

How can I make this method return JSON?

I have inserted [WebGet(ResponseFormat = WebMessageFormat.Json)], but that didn’t help

[WebGet(ResponseFormat = WebMessageFormat.Json)]  
protected override IEnumerable<KeyValuePair<string, SampleItem>> OnGetItems()  
{  
   // TODO: Change the sample implementation here  
   if (items.Count == 0)  
   {  
      items.Add("A", new SampleItem() { Value = "A" });  
      items.Add("B", new SampleItem() { Value = "B" });  
      items.Add("C", new SampleItem() { Value = "C" });  
   }  
   return this.items;  
}  
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:03:23+00:00Added an answer on May 16, 2026 at 11:03 pm

    In order for this to work, you need to host this with the webHttpBinding and the WebServiceHostFactory in your web.config and service’s *.svc file.

    You didn’t show any web.config or other config – so I cannot really tell what you’re doing. But the JSON response format in the WebGet attribute is only supported in the REST-style WCF services. The WebGet attribute is ignored for any of the SOAP-based bindings, e.g. basicHttpBinding, wsHttpBinding, netTcpBinding and so on.

    For more information on REST-style WCF Services, check out the WCF REST Developer Center and read up on how to set up and use REST-style WCF services.

    Update: in order for your *.svc file to properly work as a REST service that uses the WebGet attribute and returns JSON, you need to make sure to specify the correct service host factory:

    <%@ServiceHost Language="C#" Service="YourService"
                   Factory="System.ServiceModel.Activation.WebServiceHostFactory" %>
    

    By specifying the WebServiceHostFactory, you’re telling the WCF runtime to use this service as a REST service, and then all the other pieces should automatically fall into place.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make an ajax GET request to a WCF web service
I'm trying to make ExtJs work with backend running WCF RIA services with JSON
I'm trying to make a call to a remote WCF service from within an
I am trying to make a WCF REST method entirely asynchronous (I don't want
I am trying to make a post request to my restful WCF service. The
I'm trying to convert an ASP.Net web service to WCF application. The client is
I am trying to make a cross domain HTTP request to WCF service (that
I borrowed the following code to try to make an ajax-enabled WCF service work
I'm trying to consume a RESTful web service using WCF. I have no control
Being completely new to WCF, I'm trying to make a RESTful service which will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.