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

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

Send JSON Object to WCF

Posted By:      Posted Date: April 14, 2011    Points: 0   Category :ASP.Net

I have a WCF returning JSON correctly, however this WCF now needs to be extended to allow JSON Serialized objects to be posted to it. I am using JQuery to serialize objects and post it to the WCF, and when I run the project in Debug the method SimpleSearch() is being called and an object is being instantiated, however the properties are all null. Is there an error taking place in the deserialization from JSON?

Below is an extract of my WCF file, below this is the JavaScript calling the WCF using JQuery

[ServiceContract(Namespace = "http://www.link.co.uk/")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class ATMService {        

        [WebInvoke(RequestFormat = WebMessageFormat.Json)]
        public void SimpleSearch(SimpleObj searchRequest) {
            // Once in here the searchRequest object both Name and Postcode are null      


    public class SimpleObj {
        public string Name { get; set; }
        public string PostCode{ get; set; }

function search() {   

    var searchRequest = new Object();
    searchRequest.Name = "Chris";

    var dataToSend = '{"searchRequest":[' + JSON.stringify(searchRequest) + ']}';

        type: "PO

View Complete Post

More Related Resource Links

Send object from one page to another



I want to create object in 1.aspx, and then send it to 2.aspx. This methods are bad, because:

1)Send object with url, like this:


This is not confidential.


Session["field1"] = "12345"; // set
Object foo = Session["field1"]; // get

This is bad too, because in 2.aspx this fields send to textboxes, and if user go to 2.aspx without 1.aspx, he'll see old data. 

send data in class object from one page to another using session


hello everybody

now i hav stored all data like user name, data fatched from database of that user

and i stored that data and user name such as:

string strUserName="user name"

dataset ds =new dataset();// data of that user

now i wan yo send d whole data from my login page to user profile page

can anybody help me for that...................

and plz tell me that how much is this way is benifitial to send data from one page to another page

plz........kindly waiting for positive rply

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

make json call to send an email


the aspx:

<div class="contactSubmit">
                <asp:ImageButton ID="ibSubmit" runat="server" ValidationGroup="vgContact" /></div>


the jquery :

$(document).ready(function () {
            // Add the page method call as an onclick handler for the div.
            $(".contactSubmit").click(function () {
                    type: "POST",
                    url: "Home.aspx/GetDate",
                    data: "{}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        // Replace the div's content with the page method's return.

The problem is that I need to use the text in a text box in my webmethod, and I can't because it's static, this results in a compilation error:

    public static string SendContactForm()


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 to make my WCF client send JSON?

Hi, I have a WCF Service that accepts and sends JSON objects, defined like the following: [OperationContract] [WebInvoke(Method = "POST", UriTemplate = "/booking/", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] Int32 booking(order o); now I have used SvcUtil.exe to create a client class and using that, I am trying to access my service - but even though I use "webHttpBinding" with "webHttp" behavior, it always sends it's messages in xml. What do I have to do make my client speak JSON?  

Cannot send List inside of Dictionary

List<string> receivers = new List<string>(); foreach (object item in listBoxControl1.SelectedItems) receivers.Add((string)item); Dictionary<string, object> inArgs = new Dictionary<string, object>(); inArgs.Add("Receivers", receivers); inArgs.Add("Sender", client.name); inArgs.Add("Message", memoEdit2.Text); inArgs.Add("IsGuaranteedDelivery", true); inArgs.Add("DataType", TransmitToClientDataType.ChatMessage); if (service != null) service.AddTask("orion_send", inArgs); There is an error with serialization at last string because List<string> object. I tryed to send List<T> object via WCF, it's succesfull. But why there are problems with List<T> included to Dictionary?

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

JSON string to Object


If I have a  string  containing  valid JSON

how can I conver to an obect in c#?

How to send any collection object from .NET Application to object variable created in SSIS Package


HI All,

I have a question regarding SSIS -- How to send list object from .NET Application to object variable created in SSIS Package. In List object there are one lack records stored..This list object needs to be passed to SSIS Package. Please reply me back with any suggestion/solutions ...Required ASAP.

Waiting for your replies.





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




Problem in passing Json collection object from View to Action



I am trying to send json data from view to controller action.  But the issue is the data is not populating in the action parameter List<Score>.

View Model:
public class Score
   public int QuestionId { get; set; }
   public int PrevAnswerId { get; set; }
   public int CurrAnswerId { get; set; }
   public string CurrAnswerName { get; set; }

Json Data look like:
{QuestionId:1, PrevAnswerId:3,  CurrAnswerId:3,  CurrAnswerName:'Known to Broker'},
{QuestionId:2, PrevAnswerId:7,  CurrAnswerId:7,  CurrAnswerName:'Completed'},
{QuestionId:3, PrevAnswerId:10, CurrAnswerId:10, CurrAnswerName:'Report'}

On window load,  I will construct the Json object using "eval()" function and do some operation in the data before its save.

On Save Click, I will call the action through the ajax call.
        url: url,
        type: "GET",
        dataType: 'json',
        data: {score: ScoreJson},

I nead to send an "interface" from C++ to a managed .NET object


I have a Win32 application that loads a C++ DLL. This C++ DLL is compiled with IJW support to let me call Managed objects.  This worksperfectly and there are no problems here.  My problem is the opposite way.  I nead, from my .NET (c#)code to call back to the Win32 program.  How do I manage this?  PInvoke and COM is out of the Question.  It must be using an Interface or soething like that.


Ole Morten Heien
HD Software

------------------------------------------- Ole Morten Heien HD Software / Advisor AS -------------------------------------------

Using DataContractJsonSerializer on dynamic JSON object


I'm using the DataContractJsonSerializer and the DataContract and DataMember class atrributes to serialize some JSON sent to me from a 3rd party javascript component. All is working well except the component sends some dynamic data.


ex. { "objects": [{"object1": "value"}, {"SomeOtherObject": "anotherValue"}] ... }


What are my options for serializing this if the "object1", "SomeOtherObject" are all dynamic and I can add them into the class that I serialize to. Is it possible to get the JSON Serializer to convert this to a Dictionary<string, string>??


Also I'm using C# 3.0 so dynamics is out.

How to send an object using MSMQ and WCF service C#?


I'm trying to send an object in a queue:


PurchaseOrder po = new PurchaseOrder();
      po.CustomerId = "somecustomer.com";
      po.PONumber = Guid.NewGuid().ToString();

      PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
      lineItem1.ProductId = "Blue Widget";
      lineItem1.Quantity = 54;
      lineItem1.UnitCost = 29.99F;

      PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();
      lineItem2.ProductId = "Red Widget";
      lineItem2.Quantity = 890;
      lineItem2.UnitCost = 45.89F;

      po.orderLineItems = new PurchaseOrderLineItem[2];
      po.orderLineItems[0] = lineItem1;
      po.orderLineItems[1] = lineItem2;

      OrderProcessorClient client = new OrderProcessorClient("OrderResponseEndpoint");

      MsmqMessage<PurchaseOrder> ordermsg = new MsmqMessage<PurchaseOrder>(po);

      ordermsg.Label = "MY MESSAGE"
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