datacontractserializer

Deserializing XML with DataContractSerializer

巧了我就是萌 提交于 2019-12-17 22:49:23
问题 I have a web service that returns the following data: <?xml version=""1.0"" encoding=""UTF-8""?> <RESPONSE> <KEY>12345</KEY> <PROPERTY> <PROPERTY_ADDRESS> <STREET_NUM>25</STREET_NUM> <STREET_ADDRESS>ELM ST</STREET_ADDRESS> <STREET_PREFIX/> <STREET_NAME>ELM</STREET_NAME> <STREET_TYPE>ST</STREET_TYPE> <STREET_SUFFIX/> </PROPERTY_ADDRESS> </PROPERTY> </RESPONSE> I have a class structure to match: [DataContract(Name="RESPONSE", Namespace="")] public class Response { [DataMember(Name="KEY")]

ShouldSerialize pattern and DataContractSerializer

不羁的心 提交于 2019-12-17 19:52:30
问题 Is there a way to get the ShouldSerialize* pattern working with DataContractSerializer ? Here is a small example: I have a simple class Person which looks like this: [DataContract] public class Person { [DataMember] public string FirstName { get; set; } public bool ShouldSerializeFirstName() { return !string.IsNullOrEmpty(FirstName); } [DataMember] public string LastName { get; set; } public bool ShouldSerializeLastName() { return !string.IsNullOrEmpty(LastName); } public Person(string

how to not return null when a Data member field is not set in the data contract

对着背影说爱祢 提交于 2019-12-17 18:39:39
问题 I'm having a strange problem with my WCF service that returns data in JSON format. I want to return information about a "Customer" based on the request sent by client. Client can request what fields of information about a customer they need and the service needs to send only that information about the customer. For Example: If client asks for a list of customers and says they want firstname, lastname, city of each customer then server should send a json response with each field name and

Ignore field order in DataContractSerializer

爷,独闯天下 提交于 2019-12-17 16:32:05
问题 When deserializing, DataContractSerializer requires not only that an element name matches, but also that it is in a certain order with respect to the other elements. My application is such that every field can be uniquely identified by its name. I would therefore like it to be possible for the XML file to contain the elements in any order and for the deserializer to still work. Is it possible to set up a DataContract like this? The introductory paragraph in Data Member Order suggests that

ASP.NET Web API XmlFormatter does not work, falls back to JsonFormatter

假如想象 提交于 2019-12-14 03:10:50
问题 I have been pulling my hair out for the past two days trying to figure out why XmlFormatter (via DataContractSerializer) does not serialize data I return in my Web API method. WebAPI decides to use JSON anyway but I need the result to be in XML (as per application that will use this API). I have setup my browser to send Accept: application/xml for the resolver to use the XmlFormatter (but the result is always json). Controller: public class MyController : ApiController { public

Using JavaScriptConverter for DataContract serialization in C#

你。 提交于 2019-12-13 19:07:45
问题 I am having problem to find some information about how to get a custom converter invoked for a given property when serializing a C# object to JSON (and vice-versa). JSON looks like that: {"ws_status": "success", "result": 32} or {"ws_status": "failure", "error_code": 32123} I have my C# object: [DataContract] class WebServiceResult { [DataMember(Name = "ws_status", IsRequired = true)] public Boolean Success { get; private set; } [DataMember(Name = "error_code")] public Int32 ErrorCode { get;

Write/Restore ObservableCollection<T>

允我心安 提交于 2019-12-13 02:27:08
问题 I have huge problem with saveing and restore ObservableCollection to IsolatedData. I'm trying with this code. Helper class for Observable public class ListItem { public String Title { get; set; } public bool Checked { get; set; } public ListItem(String title, bool isChecked=false) { Title = title; Checked = isChecked; } private ListItem() { } } IsoHelper public class IsoStoreHelper { private static IsolatedStorageFile _isoStore; public static IsolatedStorageFile IsoStore { get { return

DatacontractSerializer in Java

两盒软妹~` 提交于 2019-12-12 12:26:56
问题 Is there a method or library in Java which can desirialize .net object wich was serialized by DataContractSerializer? My Situation: I want to create a java-client wich can communicate with microsoft MQ (MSMQ) over http. I want to use the DataContractSerializer in .Net and an Serializer in Java so that .Net can read the content of the message which is serialized by java. 回答1: My solution was to use the jackson json serializer. Additionally i use the Bson4jackson library to serialize byte

XSLT: Using parent node's namespace

家住魔仙堡 提交于 2019-12-12 04:58:25
问题 I would like to avoid producing a repeated namespace in my XSLT output. (I am using XSLT to massage some XML so that Microsoft's DataContractSerializer sees fit to actually process it properly. One of the things that the DCS doesn't seem to like is defining the same namespace multiple times.) I am taking all of the "Characteristics" elements from under the XXX element and grouping them together in a new array element like so: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL

Datacontract serialization/serialization with images

给你一囗甜甜゛ 提交于 2019-12-12 01:43:17
问题 I have a class with an image that has to be (sometimes) serialized/deserialized according to the fact that the image is embedded or not. [DataContract(IsReference = true)] public class Data { [DataContract(IsReference = true)] public class MyImage { [DataMember] int WidthStorage [DataMember] int HeightStorage; [DataMember] public string strImageLocation; [DataMember] public Image ImageEmbedded = new Image();<----- not working null public bool GetImage(Image image, int width, int height) { ...