datacontract

Portable class library: recommended replacement for [Serializable]

早过忘川 提交于 2019-11-28 04:29:17
I am porting a .NET Framework C# class library to a Portable Class Library. One recurring problem is how to deal with classes decorated with the [Serializable] attribute, since this attribute is not part of the Portable Class Library subset. Serialization functionality in the Portable Class Library subset instead appears to be covered by DataContractAttribute . To preserve as much of functionality as possible in the Portable Class Library, is it sufficient to replace [Serializable] with the [DataContract] attribute (with the implication that all fields and properties subject to serialization

Generate DataContract from XSD

匆匆过客 提交于 2019-11-28 04:09:47
I want to be able to generate a DataContract from a XSD file, preferably using the xsd.exe tool . What is the easiest way for it to auto generate the [DataContract] and [DataMember] on each of my items? Or is there a better approach? I am trying to avoid having to recreate the data contract each time the XSD file is changed and regenerated. marc_s The xsd.exe tool predates WCF and doesn't know anything about [DataContract] and [DataMember] . If you do use xsd.exe , you'll have to switch WCF to use the XmlSerializer instead of its default DataContractSerializer for serializing the data

Deserializing an IEnumerable<T> with [DataContract] applied does not work

穿精又带淫゛_ 提交于 2019-11-28 02:06:53
Rather new to Json.net and tried the following simple example serializing and then deserialing an object getting the error below: using Microsoft.VisualStudio.TestTools.UnitTesting; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; using System.Text; using System.Collections; namespace Timehunter.Base.ServicesTests { /// <summary> /// Summary description for JsonError /// </summary> [TestClass] public class JsonError { [TestMethod] public void TestMethod1() { JsonSerializerSettings serializerSettings = new

Custom serialization with DataContractSerializer

两盒软妹~` 提交于 2019-11-27 23:52:27
问题 I'm currently using wrapper classes for my DataSets ,in order to implement custom serialization. I would like to use DataContractSerializer (more like have to use it) but still support the custom serialization. The problem is that the [DataContract] and [Serializable] attributes don't seem to get along so well... how could I override the serialization, and support BOTH DataContract & ISerializable serialization? The code for the wrapper DataSet class is brought here: [Serializable()] [System

How to serialize/deserialize a C# WCF DataContract to/from XML

我是研究僧i 提交于 2019-11-27 23:36:15
问题 I am developing a WCF service which will be consumed by multiple different client applications. In order to make one functionality work, the server needs to read an XML file into a C# DataContract which is then passed on to the concerned client. As far as I understand from the MSDN website, this is possible but I couldn't find any complete examples. In particular, the website talks about a 'stream' parameter which I don't quite get yet. My data contract has one property field which is a list

Constructor in WCF DataContract not reflected on Client

陌路散爱 提交于 2019-11-27 21:34:29
I need to have some data members get some values when I create an instance of the DataContract on the client. This is not happening using constructors. I have searched through different forums and found we have to use [OnDeserializing] and [OnDeserialized] attributes. This is also not working. Can somebody suggest something here. The other alternative is creating constructors in the partial classes at the client side. I want to avoid that. Please find the code below: Server-side: Datacontract [DataContract] public class Account { private int mAccountId; private string mAccountName; public

IsReference property in data contract

ぐ巨炮叔叔 提交于 2019-11-27 20:59:17
What is the purpose of IsReference property in DataContract ? How does the request and response vary with this property applied? Tanner It determines how objects are serialized, by default, IsReference=false . Setting IsReference = true allows the serialization of trees of objects that can reference each other. So with a list of Employees that each have a property for Manager (who is also an Employee ), a reference to the Manager for each Employee can be held rather than embedding the Manager within each Employee node: IsReference=false would produce: <Employee> <Manager i:nil=“true“ /> <Name

WCF Message & Data Contract, DTO, domain model, and shared assemblies

情到浓时终转凉″ 提交于 2019-11-27 17:03:50
问题 I have a web client that calls my WCF business service layer, which in turn, calls external WCF services to get the actual data. Initially, I thought I would use DTOs and have separate business entities in the different layers... but I'm finding that the trivial examples advocating for DTOs, to be, well, trivial. I see too much duplicate code and not much benefit. Consider my Domain: Example Domain I have a single UI screen (Asp.net MVC View) that shows a patient's list of medications, the

Naming Generic DataContracts in WCF

别等时光非礼了梦想. 提交于 2019-11-27 12:57:12
问题 I am using a Generic Class as a Response Data Contract. All is good and this is streamlining the design of my WCF service significantly. Each request is given a standard response object with the following signature: Status (Enum) Message (String) Result (T) Below is the Response Class: [DataContract] public class Response<T> { public Response() {} public Response(T result) { this.result = result; if (result != null) { this.status = Status.StatusEnum.Success; } else { this.status = Status

How to use Custom Serialization or Deserialization in WCF to force a new instance on every property of a datacontact ?

☆樱花仙子☆ 提交于 2019-11-27 08:57:35
I have a datacontact with many members that has a custom class I would like to force a new instance if the property is null on deserialization. is there a way to do that? Surjit Samra If your are using DataContract serialization then you can override its default behaviour using the OnDeserialized attribute. From MSDN : When applied to a method, specifies that the method is called during deserialization of an object in an object graph. The order of deserialization relative to other objects in the graph is non-deterministic. Here is my sample code: namespace MySpace { public class MyCustomClass