Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Returning JSON From RESTful WCF

Returning JSON From RESTful WCF

Scheduled Pinned Locked Moved C#
csharpjavascriptwcfjson
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Liagapi
    wrote on last edited by
    #1

    I created a RESTful WCF Service and made sure that the data returned from it is of type JSON by setting its ResponseFormat property equal to WebMessageFormat.Json in my WCF Service as follows:

    ResponseFormat = WebMessageFormat.Json

    I checked to ensure that data returned from the WCF Service is indeed JSON by using Fiddler. What I don't understand is if the return type of the data is JSON then why do I need to convert it to a JSON string using JSON.stringify() in my jQuery AJAX call.

    A 1 Reply Last reply
    0
    • L Liagapi

      I created a RESTful WCF Service and made sure that the data returned from it is of type JSON by setting its ResponseFormat property equal to WebMessageFormat.Json in my WCF Service as follows:

      ResponseFormat = WebMessageFormat.Json

      I checked to ensure that data returned from the WCF Service is indeed JSON by using Fiddler. What I don't understand is if the return type of the data is JSON then why do I need to convert it to a JSON string using JSON.stringify() in my jQuery AJAX call.

      A Offline
      A Offline
      Afzaal Ahmad Zeeshan
      wrote on last edited by
      #2

      First of all, you did not share the output response of the service, and we have no idea what is going wrong there. Many things can go wrong, such as the C# code might be deserializing the JSON to an object and providing you with that object. Also, the only purpose of JSON.stringify is to serialize the objects, if you are going to render the objects or their properties on the screen, there is no need to serialize the object at all. It would be a good idea to see the output of this,

      success: function (response) {
      alert(response); // <-- Here.
      }

      This will either show [object Object], or some valid JSON document. That will give you an idea of the type of data that is being passed here.

      The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

      L 1 Reply Last reply
      0
      • A Afzaal Ahmad Zeeshan

        First of all, you did not share the output response of the service, and we have no idea what is going wrong there. Many things can go wrong, such as the C# code might be deserializing the JSON to an object and providing you with that object. Also, the only purpose of JSON.stringify is to serialize the objects, if you are going to render the objects or their properties on the screen, there is no need to serialize the object at all. It would be a good idea to see the output of this,

        success: function (response) {
        alert(response); // <-- Here.
        }

        This will either show [object Object], or some valid JSON document. That will give you an idea of the type of data that is being passed here.

        The shit I complain about It's like there ain't a cloud in the sky and it's raining out - Eminem ~! Firewall !~

        L Offline
        L Offline
        Liagapi
        wrote on last edited by
        #3

        Thank you so much for your reply. I can now see that the data I received from the AJAX call is indeed JSON.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups