WCF And Json / Wrong Serialization
Feb 2, 2010
Why this WCF 3.5 method
[ServiceContract]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Json
{
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public string Upper(string text)
{
return text.ToUpper();
}
}
returns {"d":"TEXT"} ?
It should returns {"TEXT"}
I'm calling using jQuery.
$("#upper").click(function() {
$.ajax({
type: "GET",
url: "/Json.svc/Upper?text="+$("#input1").val(),
success: function(data) {
$("#input1").val(data.d);
}
});
});
View 2 Replies
Similar Messages:
Feb 12, 2010
I'm trying some WCF ajax.net 3.5 out for the first time, and I'm having some difficulties. I have a WCF Service which I have connected to in my aspx page using <asp:ScriptManager>. I have a custom object which has been decorated as a [DataContract]. I'm calling the object from javascript successfully, I can see the JSON response in FireBug, but Sys.Serialization.JavaScriptSerializer.deserialize() chokes on it. I'm sure I'm making a noob mistake, but I used up all my patience getting the Web.Config values right for running the WCF service.
Here's a mockup of what I'm doing.
[Code]....
View 3 Replies
Jul 16, 2010
in Json.net we can rename the property with [JsonPropertyAttribute("")] ,
public class Foo
{
// how can I rename the Foo1 property name to F1?!
public string Foo1 { set; get; }
public string Foo2 { set; get; }
}
and in the web service code behind :
[WebMethod]
public List<Foo> GetFoos()
{
List<Foo> post = new List<Foo>
{
new Foo(),
new Foo(),
new Foo()
};
return post;
}
View 1 Replies
Mar 14, 2010
I have a class that contains an enum property, and upon serializing the object using JavaScriptSerializer, my json result contains the integer value of the enumeration rather than its string "name". Is there a way to get the enum as a string in my json without having to create a custom JavaScriptConverter? Perhaps there's an attribute that I could decorate the enum definition, or object property, with?As an example:
enum Gender { Male, Female }
class Person
{
[code]...
View 2 Replies
Aug 4, 2010
I am using .Net Framework 3.5 on an ASP.net web project using jquery.ajax to make web service calls. My web service returns objects serialized as JSON by specifying the content type of my POST as "application/json". I would like just one of my many properties to return a non quoted javascript function name instead of a quoted string. Serialized as such:
{"dataInit": functionName, "id": "myID"}
instead of
{"dataInit": "functionName", "id":"myID"}
View 2 Replies
Mar 1, 2010
I want to use the DataContractJsonSerializer class. This is contained within theSystem.Runtime.Serialization.Json namespace and the System.ServiceModel.Web dll.or some reason, when I add the using directive for the namespace, Visual Studio says it doesn't recognise the Json namespace in System.Runtime.Serialization.When I try to add the System.ServiceModel dll, nothing happens, which suggests to me it's already referenced. (Because nothing also happens when I try to add a reference to System.Web which is definitely referenced!)
View 6 Replies
Apr 27, 2010
I'm getting the error from the subject line when I try to move some code that formerly lived in the App_Code directory to an external library (that would be moved into the /bin directory). What do I need to include or reference to get rid of this error?
I've already included: System.Runtim.Serialization (says it's version 3.0.0, I don't see a version 3.5.0 anywhere).
View 1 Replies
Aug 1, 2010
I have a weird thing happening. I have two identical databases installed on one virtual machine but under two different instances of SQLServer. For some reason, periodically when saving from one it will save to the other instead. Using debug, I have verified that the connection string is correct and when the item saves, it still saves to the wrong database.I use session variable, and am of the belief that it might have something to do with it...and t hat when I go from one to the other it is still getting the connection string form the other for some reason.To make sure that it isn't a problem, I make sure that I completely close out one database before opening the other in a new IE window.I assume that when I completely close out an internet explorer window that it abandons all session states. Is that true?
View 7 Replies
Nov 25, 2010
I am trying to get jStree (jQuery tree control) working in my ASP.NET (C#) page. I'm using a WCF service to return a test string of JSON. Opening the WCF service URL in the browser works fine - If I go to the URL (http://localhost/website/GetTree) I get the JSON (looks just like opening XML in browser, with syntax highlighting and collapsible tab thingys)
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">{"attr": { "id": 2, "rel": "default" }, "data": "A node", "children": [ { "data": "Child 1", "attr": { "id": 43, "rel": "document" } }, {"data": "Child 2", "attr": { "id": 25, "rel": "document"} } ] }</string>
jstree itself works fine - if I put the same JSON in "manually" in my document.ready like so:
"json_data": {
"data":
[{
"attr": { "id": 2, "rel": "default" },
"data": "A node",
"children":
[{
"data": "Child 1", "attr": { "id": 43, "rel": "document" }
},{
"data": "Child 2", "attr": { "id": 25, "rel": "document"}
}]},{
"attr": { "id": "li.node.id", "rel": "document" },
"data": {
"title": "Long format demo",
"attr": { "href": "#" }
}}]},
I get the tree appearing with those nodes in it.
But, combining the two:
"json_data": {
"ajax": {
"url": "GetTree",
"data": function (n) {
return {
};
}
}
},
fails. The jstree shows up as just the word "loading..." and an animated loading gif. And it does hit a breakpoint inside the WCF service method (just like browsing to it does).
A: An idea where I've gone wrong?
B: An idea how I find out what's wrong? jstree documentation was no , and I can't see any error messages.
Update: solved
[Code]....
View 1 Replies
Aug 11, 2010
I try to use the jquery + json to get all elements in form and build a JSON var to post in a ASP.NET MVC method.
[Code]....
It method get all fields in a form and build a JSON, but it dont put JSON inside JSON.
Example:
If i have the follow form:
<input name="person.name"><input name="person.age"><input name="person.address.street">
The serialized string build a JSON like this
{ "person.name": "??", "person.age": "??", "person.address.street": "??" }
I need a plugin or some function to generate like this:
{ "person": { "name" : "??", "age" : "??", "address":{ "street": "??" } } }
View 1 Replies
Aug 1, 2010
I have a very weird thing happening. I have two databases that have exactly the same tables but different database names on the same virtual machine, but in different instances of SQL Server. For some reason, when using one of them, it will save to the other. In debug, looking at my connection string..I have verified that it is correct, yet when I allow the save, I look in the table and it isn't there, it is in the other database that is in a table with a completely different name and in a different instance of SQL Server.
View 1 Replies
Dec 29, 2010
I have a text file named gisQuery129.json that is created using Json.NET - [URL] There is an example on how to create a JSON file and I have done that successfully, but I want to read the file on a page load event and add the values to .NET textbox controls for input values in a query. The created file looks like the following:
{
"myData": {
"randomNumber": "129",
"Application": "MyMapApp",
"FeatureId": "ALL",
"Feature": "ALL",
"spatialQuery": "FEATURE_ID= '11111' AND REQ_SEQ_NUM= 1 AND RAND_PARAM= 129 OR FEATURE_ID= '22222' AND REQ_SEQ_NUM= 2 AND RAND_PARAM= 129"
}
}
I want to read the data in the above sample JSON data and then populate my textboxes something like this:
txtRandParam.text = "129"
txtApplication.text = "MyMapApp" and three more text boxes after that.
View 4 Replies
Feb 1, 2010
I want to retreive the data from database and assign it to dropdownlist. For that I'm using the following jquery in the onclick event
[Code]....
View 1 Replies
Jan 21, 2011
I use the JavaScriptSerializer class of ASP.net to serialize my object and return it to the client side. How can I deserialize the string using JavaScript?
View 4 Replies
Apr 4, 2011
In my javascript code I am getting json string from cs file
var tmpString="<%=resultset2%>";
In cs I am concatenating strings to build json string. Here is an issue the json string is returned as a string and it has " with it.
"[{id:'1',name:'Aik'},{id:'2',name:'Aik or Aik'}]"
Because of " in beginning and end javascript code treat it as a string.
View 2 Replies
Nov 18, 2010
I've been tasked with implementing a JSON feed on an asp.net website that will be consumed by 3rd party apps (such as IPhone, Android, etc) and I'd like to follow best practices.
An example of what I'd like to achieve would be something similar to: [URL]
I've chosen the JSON.net api as this seems to be highly recommended.
My Google-fu must be failing me as I can't find a single full example code for an Asp.net web application with JSON.net implemented on it, so I've no real concept of where to begin.
My question is fairly simple:
Should I create this sort of feed as an ASPX, or ASHX file? Or even a .NET Web Service? (Remember that the tools that will be using this feed are on external apps like IPhones, etc)
I created a test feed in both ASHX and ASPX format ... here is the code (I'm using Subsonic to populate the collection) ... are either of these along the correct lines?
ASPX:
[Code]...
View 2 Replies
Apr 26, 2010
is it possible to use WCF classes with attributes (like [DataMember....) then you wouldnt need to do seralization on the client side (jquery) ?
View 1 Replies
May 24, 2010
I am using business objects that are accessed via webservices. These objects can be loaded via the webservice and serialized to my mvc app. The mvc app can get a web reference to the objects and they can be utilized in the mvc app. However, the business objects are where the classes are defined, and where the annotations are applied.
The mvc validation seems to have no idea that there are System.ComponentModel.DataAnnotations attributes applied to this business object class.
1) Are DataAnnotations lost when objects are serialized / deserialized?
2) If in mvc I use a view model approach, and have nested objects (which themselves have public properties - decorated with DataAnnotations) can/will the mvc validation system traverse the entire object model, the model being used for my view? (so it can see DataAnnotations attributes of the nested object)?
View 1 Replies
May 22, 2010
I had an interview Thursday and one questions that I was asked in the technical interview was a little confusing.
First, he asked me about Viewstate and I explained to him what all that entailed.
He then asked me what happens if the data you are putting into the Viewstate gets to big.
I told him you could then use Sessions or start storing things in the Database.
He said, what about Data Compression? I immediately responded by saying, yes you can use Serialization/Deserialization to store/retrieve the data (i'm using that in my open source project).
When he says "Data Compression", is he talking about "Serialization" or is this something different?
View 9 Replies
Jan 19, 2011
Code:
public class GroupInfo
{
private List<Structure> _sectors = new List<Structure>();
[XmlElement("Sector")]
public List<Structure> Sectors
{ get; set; }
[XmlElement("Person")]
public List<Users> Person
{ get; set; }
[code]...
View 10 Replies
Jan 21, 2010
I want users to be able to export data as an XML file. Of course I want them to be able to later on import that same XML file however they always could change it or it could be a different XML file. So I want to validate the XML file to check if it is in the format that I expect. So I guess I would need something like a schema to check just that it has to be through code. So if I expect
<Root>
<Something>
<SomethingElse> </SomethingElse>
</Something>
</Root>
I don't want some other format to be in the file other then the one I expect. Also how would I validate fields? Like say I require that there must be some text in between tags. If it is blank the file is not valid. So how could I do this?
I decided to use XML serialization so I know it will through an exception if it is the wrong format and ignore stuff that does not work. However I am not sure should I just go through it and C# to validate each of the records or should I try to make an xml schema to do it. If I would want to do it through an xml schema with xml serialization how would that work? Like Do I first do something like I seen in the responses then de serialize it? Or how would I do it?
View 5 Replies
Apr 19, 2010
what is means of serialization mode in LINQ to SQL?
what architecture does LINQ to SQL uses internally (connected or disconnected architecture)?
View 1 Replies
Nov 12, 2010
I follow the code snippet to calculate Session size. Profile Memory Usage of Session State ASP.Net My problem is some properties of objects aren't marked as Serializable so I cannot apply the solution. Can I just bypass non-serializable properties?
View 1 Replies
Feb 14, 2011
I am having a lot of trouble with WCF web service over SSL / HTTPS, so I was wondering if (as a quick fix) I could serialize the object, convert that to a byte array, encrypt the array, pass the encrypted array.
On the other side receive the encrypted array, decrypt the array, convert from the array and then deserialize the object.
View 1 Replies
Mar 7, 2011
I'm attempting to serialize an object but I would like to exclude one of the objects inside it. I've tried [NonSerialized] and it is still attempting to serialize it when I call XmlSerialize on a Cart object.
[Serializable]
[XmlRoot("Cart")]
public class Cart : ICart
{
// Public Properties
[DefaultValue("")]
public string ID { set; get; }
[XmlIgnore()]
[NonSerialized]
public CartSerializer Serializer = new CartSerializer(this);
}
View 1 Replies