datacontractserializer

Is there a way to override how DataContractJsonSerializer serializes Dates?

微笑、不失礼 提交于 2019-12-04 23:39:08
Is there a way to change how the DataContractJsonSerializer serializes dates? Currently, it'll convert a date to something like: { "date": "/Date(1260597600000-0600)/" } I would rather have it serialize as just the milliseconds since utc 1970. That way, other languages can easily work with the json data. No, there's no hook in the serializer itself to do that. But you can use some of the serialization callbacks to implement this same behavior. You'd create another data member (of type string), and before the data is serialized, an [OnSerializing] callback would be invoked to copy the value of

Object hierarchy returned by WCF Service is different than expected

牧云@^-^@ 提交于 2019-12-04 17:18:12
My understanding may be wrong, but I thought once you applied the correct attributes the DataContractSerializer would render fully-qualified instances back to the caller. The code runs and the objects return. But oddly enough, once I look at the returned objects I noticed the namespacing disappeared and the object-hierarchy being exposed through the (web applications) service reference seems to become "flat" (somehow). Now, I expect this from a web-service…but not through WCF. Of course, my understanding of what WCF can do may be wrong. ...please keep in mind I'm still experimenting with all

MS JSON date serialization and daylight saving time

牧云@^-^@ 提交于 2019-12-04 12:58:35
We have an Ajax web service hosted in an ASP.NET application. This service accepts a DateTime parameter which, for the purposes of this question, should receive the DateTime equivalent of /Date(1359727200000-0200)/ , which is a MS-JSON literal for Feb 1, 2013 9:00 AM in Brazil time. This literal is what the browser sends within the Ajax request. But instead of receiving that date and time, the argument passed to the service method is Feb 1, 2013 12:00 PM . To make matters worse, the argument's DateTimeKind is Local . It would be understandable if it were Utc , but even that would be incorrect

XmlSerializer vs DataContractSerializer

[亡魂溺海] 提交于 2019-12-04 12:13:33
I just realized that DataContractSerializer expects nodes in the alphabetical order or the specified order. Is there any way i could make it NOT do it? TIA kbrimington I don't think so. You may find the discussion on this question informative: Ignore field order in DataContractSerializer I used IDispatchMessageInspector.AfterReceiveRequest to intercept the message and sort it alphabetically. 来源: https://stackoverflow.com/questions/3570729/xmlserializer-vs-datacontractserializer

Can I force svcutil.exe to generate data contracts for a WCF service?

瘦欲@ 提交于 2019-12-04 06:08:42
I would like to force svcutil to generate all data contracts in an assembly that is used by WCF, regardless of whether or not a type is referenced by a given operation contract. [DataContract] public class Foo { } [DataContract] public class Bar : Foo { } [ServiceContract] public interface IService { [OperationContract] void Get(Foo foo); } Given this setup I cannot get svcutil to generate a version of Bar as there are no operation contracts that currently reference it. Is there a way to force svcutil to generate the data contract for Bar ? Add a KnownType attribute to the Foo class [KnownType

DataContract model binding to JSON in ASP.NET MVC Action Method Arguments

╄→尐↘猪︶ㄣ 提交于 2019-12-04 04:59:01
MVC3 comes out of the box with JsonValueProviderFactory() which is very handy for binding incoming JSON to a model. Unfortunately, I can't figure out how to setup model contracts with names that differ from the incoming JSON. For example: [DataContract(Name = "session")] public class FacebookSession { [DataMember(Name = "access_token")] public string AccessToken { get; set; } [DataMember(Name = "expires")] public int? Expires { get; set; } [DataMember(Name = "secret")] public string Secret { get; set; } [DataMember(Name = "session_key")] public string Sessionkey { get; set; } [DataMember(Name

RuntimeType:http://schemas.datacontract.org/2004/07/System' is not expected

∥☆過路亽.° 提交于 2019-12-04 04:45:35
Ok so I got DataContractSerializer working with my object graph. See my previous questions for more information. Serialization / Derialization of a tree structure The deserializer has no knowlege of any type that maps to this contract However, one of my fields, _UserPropertyDefinitions , is defined as shown below.. It defines a list of custom properties that this user can add to objects in the data structure. The string is a unique key to identify the property, and Type is the type of the property which is always a primative type like Bool, Int, String etc etc.. Each object has a corresponding

DataContractJsonSerializer to skip nodes with null values

こ雲淡風輕ζ 提交于 2019-12-03 23:29:17
问题 I am using DataContractJsonSerializer to serialize my custom object to JSON. But i want to skip the data members whose values are null . If DataMember is null that node should not come in JSON string. How can I achieve this? Give me a simple code snippet to work with. 回答1: You can use the EmitDefaultValue = false property in the [DataMember] attribute. For members marked with that attribute, their values will not be output. [DataContract] public class MyType { [DataMember(EmitDefaultValue =

Configuring WCF client and service for use with protobuf-net

白昼怎懂夜的黑 提交于 2019-12-03 20:29:56
问题 I decided to open a new question about this matter, maybe expanding this question, not having found a precise answer about the issue anywhere on the Internet. I want to use protobuf-net to serialize/deserialize messages exchanged between my WCF client and service. The service is self-hosted in a Windows Service. Both client and service are configured programmatically, using a custom binding very similar to wsHttpBinding . Service reference code is generated using "Add Service Reference"

WCF DataContractSerializer doesn't pick up contract attributes… why not?

我怕爱的太早我们不能终老 提交于 2019-12-03 20:00:20
I have the following type which I use as a message contract in WCF: [MessageContract(IsWrapped = true, WrapperNamespace = "http://example.com/services", WrapperName = "EchoRequest")] public class EchoRequest { public EchoRequest() { } public EchoRequest(String value) { Value = value; } [MessageBodyMember(Name = "Value", Namespace = "http://example.com/services", Order = 0)] public String Value { get; set; } } When I generate a proxy to this type using svcutil.exe , I get a client which is able to communicate to a service which hosts it, with the XML namespaces on the elements correct according