.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

How to return serialized JSON object from WCF

Posted By:      Posted Date: May 22, 2011    Points: 0   Category :Windows Application


I am able to return the JSON string from the wcf. But i want to return the JSON object from wcf.

Is is possible to return the JSON object from the wcf? If yes , then how?


Thanks in advance..... 

View Complete Post

More Related Resource Links

How to use return JSON object from web service as a declared Type?

Hi, I just hit the following issue: I am calling a web service that returns a serialized JSON object let's say: __type, FirstName, LastName (.net object Person with properties FirstName and LastName). __type's value is Test.Person I have created a JS object using Type.registerNameSpace/registerClass called Demo.Person and it is registered on the page using the ScriptManager. Everything is working fine; I am able to get data from the server on the call back. Is it possible to make the returned object from the web service be an instance of the declared JavaScript Demo.Person class? The idea would be to call a method like result.getFullName() on the client side without having to copy all the properties. This is just a simple scenario for more complex objects.   Thanks,   Teo

Posting data to ASMX and return Object for jQuery


I am using fluent NHibernate with WebForms and I am trying to build a page where I allow a user to post a status update on their profile page and I a using a .asmx WebService to post the data to the database and then returnig a StatusUpdate instance to the page to be used by jQuery. I have a couple problems.

1) First off when I return a string from the WebService(i was testing) the textbox where the user enters their status doesnt empty the contents. And since the page doesnt refresh even if I manally clear out the textbox and put in something else, it still posts the previous status to the database again. How do I fix this?

2) Secondly, when I return the StatusUpdate Object from the Webservice I cant the results to display anything. Like I sad, Im using jQuery to make an AJX call to the WebService.

Here is my code:

User Profile Page:

Status: <asp:Label ID="status" runat="server"></asp:Label><span style="font-size:.7em;"><asp:Label ID="statustime" runat="server"></asp:Label></span><br />
<textarea id="statusBox" rows="3" cols="40"></textarea><br />
<input type="button" value="Update Status" onclick="SetStatus(); return false;

JSON Deserialize into Entity Framework Object and setting the DataMemberAttribute "Name="




I'm in the process of deserializing a JSON object into an Entity Framework object.  The property names in the JSON do not match up totally with the property names in the Entity Framework Objects. What I'd like to do is set "Name=" on the  "DataContractAttribute" for the table and the "DataMemberAttribute" for the properties in the Designer.cs file.  I tried setting these in the Designer.cs file manually just to see if it would work - which it did (using JSON.Net) but of course when I went into the .edmx designer I lost all my changes.  Is there a way to do this?


Thanks in advance

How to: Serialize Hashtable contained inside another object that is serialized as an array of object

Update:  I've added the entire program in a single block of C# text near the end of these posts that can be placed into a C# Program.cs file of a console project.   I have a class called MyHashtable that inherits from Hashtable and implements IXmlSerializable.  MyHashtable is contained inside another object called MyObject and I need to xml serialize an array of MyObject[].  Whenever I xml deserialize, the hashtable is deserialized, but only 1 of MyObjects from the MyObject[] array is deserialized.  The ReadXml uses "while (reader.NodeType != XmlNodeType.EndElement)" so I don't think the reader is consuming all of the xml internally.   Does anyone know why this is happening?  Thanks.    

Deserialize JSON object in C#

Hi, I am new to JSON and one of my service is returning JSON object as a string to my application. I need to Deserialize JSON object in C#. My JSON string is in the current format. string str = "{\"candidates\":[{\"address\":\"1580 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.42054,\"y\":37.7745960000001},\"score\":40,\"attributes\":{}},{\"address\":\"1576 MARKET ST, SAN FRANCISCO, CA, 94102\",\"location\":{\"x\":-122.420355,\"y\":37.7747030000001},\"score\":40,\"attributes\":{}}]}"; Can anyone please help me how to get all the address, locations, score and attributes from the above string. Thankyou, Ravi.

How could I deserialize a object which is serialized in JAVA??

When I try to do it with the code below. FileStream fileStream = new FileStream( "C:\\apps\\user.tmp", FileMode.Open, FileAccess.Read, FileShare.Read);     BinaryFormatter bf=new BinaryFormatter();     pd = (PianoData)bf.Deserialize(fileStream);     System.Console.WriteLine();     fileStream.Close(); Exception occurred as I had excepted. "The input stream is not a valid binary format."   I wonder if I can do it by another way

IE 8 partially cut of my JSON data return from WCF service

Hi All, I am not so sure here is the right place to post my issue. I am using ExtJS treepanel and ajax call to wcf webservice and return JSON array. My service return array. If array count is less than 2, then IE partially cut of my JSON data return from WCF service. But FireFox is working fine with same JSON format string. Very interesting thing is that I try to debug with Fildder. so I have to put "." dot in my url "http://localhost{.}:1234/ then It is working fine.   I am testing with IE8. Here is the JSON format return from FF and FireBug. {"result":[{"href":"..\/EMP\/EmployeeSearch.aspx","iconCls":"","id":"8c362443-7bb3-427e-910c-87b391c6abf5","leaf":true,"text":"Employees"}]} Here is the corrupted JSON string retrun from IE using developer tool. {"result":[{"href":"..\/EMP\/E" [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "GetSiteMap", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] [return: MessageParameter(Name = "result")] List<TreeView> GetSiteMap(string node);

how to query return all data in Array Object ,Collection Object

how to query return all data in Array Object ,Hash Table ,And DataTable dataRowSelect * From Doc a

Make my WCF service return json

Iam trying to make my wcf serivce method to return JASON-object, but it dosen't work, when I open in a webbrowser it shows xml. How can I make this method to return json.I have inserted [WebGet(ResponseFormat = WebMessageFormat.Json)],,,, but it 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; }[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" });  &nb

MVC - Return Array Json

  function SaveDataToArray1(VungNguyenLieu, DienTich,LoaiGiong,
                                 SanLuong, TGXuongGiong, TGThuHoach) 
            var arr = new Array(arrData.length,
                                VungNguyenLieu, DienTich,LoaiGiong,
                                 SanLuong, TGXuongGiong, TGThuHoach);

        function ReloadGrid1() {
            $('#tbNoiDung tbody').html("");
            for (i = 0; i < arrData1.length; i++) {
                var tbRow = "<tr>";
                tbRow += "<td align=\"center\">" + (i + 1) + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][1] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][2] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][3] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][4] + "</td>";
                tbRow += "<td align=\"center\">" + arrData[i][5] + "</td>";
                tbRow += "<td align=\"center\"

'Object graph for type 'TYPE' contains cycles and cannot be serialized if reference tracking is d



I have datacontracts as below

  public abstract class ThisClass
    public abstract ThisClass Parent { get; set; }

  public class SomeClass: ThisClass
    public abstract ThisClass Parent { get; set; }


I tried solutions in below blogs


as well as I tried to apply ..[DataContract(IsReferece = true)]

But still i get below error message in SVC trace.

There was an error while trying to serialize parameter http://tempuri.org/:data. The InnerException message was 'Object graph for type 'SomeClass' contains cycles and cannot be serialized if reference tracking is disabled

Anybody has tried above scenario?

Please help, thanks in advance.

Regards, Nakul

Is there WPF text object that use/return stringBuilder?


TextBox/TextBlock .Text returns string

if i wanna manipulate a large bunch of string, stringBuilder should be the thing to be used, but is there an ui control use/return this object as well?

JSON string to Object


If I have a  string  containing  valid JSON

how can I conver to an obect in c#?

.net 2010 REST WCF - json does not return the root List type



I am using the .net 2010 WCF Rest Service Application template to create my services.

The service needs to support two return format - xml and json which 2010 easily handles by changing the Accept value in the header info.

I have the following class structure

   public class ri
        public string nm { get; set; }

        public string nval { get; set; }

        public string cnt { get; set; }

    public class r
        public string val { get; set; }

        public string nm { get; set; }

        public List<ri> ri { get; set; }

   public class refinements
        public List<r> refs { get; set; }

   public class GetRefinementsSvc
        [WebGet(UriTemplate = "")]
        public refinements GetCollection

How to get Datetime From Json Object.


Hi All

 I am calling an action from JQuery using $.getJSON() method.

This action returns a JsonResult object.

I am getting all the values correctly but not the Date Format.

Below is the Date format which i am getting.



But i want it like "10/15/2010 11:56 AM" this format.

How can i achieve it.....Please Help

Bind Repeater Control with JSON object


I have dropdown in the aspx page. I am calling JQuery on dropdown chnage and JQuery is calling GenericHandler.ashx . The Handler is retuns 

Serialize JSON  string. I ned to bind  my Repeater control with this JOSN object any can have idea . could you please help fro me. here I am giving  my sample aspx page code

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>

<script type="text/javascript"  src="Shared/jquery-1.4.2.js" ></script>
<script type="text/javascript">
    var _entityId = 1;
    var _rowCount  = 5;
  var _pageIndex  = 8;

MVC3 + How to pass JSON Object as dictionorary object


In MVC3 Beta version i have action result same like

public ActionResult Save(Dictionary<string, string> dicObject)


I want to pass JSON Object in POST Method from javascript and need to get as dictionoray object


How can i do this? can you write example if possible?


Its urgent, please hep me




ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend