datacontract

DataContract/DataMember multiple elements in xml

血红的双手。 提交于 2019-12-11 04:25:23
问题 I have an XML like this: <data> <foo>some value</foo> <result>...</result> <result>...</result> <result>...</result> ... </data> I would like to deserialize it with DataContract/DataMember.. I know how to handle the array/collection of results elements if they were embedded inside a parent object like: <data> <foo>some value</foo> <collectionOfResults> <result>...</result> <result>...</result> <result>...</result> ... </collectionOfResults> </data> But I don't know how to do it without the

DataContract surrogate for amplified value type

末鹿安然 提交于 2019-12-11 03:08:32
问题 I want to use a custom aplified type (think Nullable) in a DataContract class. I tried to write a IDataContractSurrogate but it fails at deserialization. My amplified type looks like this: public struct Amplified<TValue> { public TValue Value { get; set; } //... some special code ... } And a DataContract may look like this: [DataContract] public class MyDTO { [DataMember] public Amplified<string> SpecialString { get; set; } } The above code works but produces unnecessary nesting with the

DataContract Parent reference in child property - how to avoid infinite serialization loop

六眼飞鱼酱① 提交于 2019-12-11 02:18:29
问题 In a WCF service, I have a situation where there is a datacontract (object) that contains a collection of child items (where the collection has a datamemeber attribute). The objects in the child collection have a reference to the parent as a property. If the parent object child collection is empty or contains a null parent reference, all is good, but if the parent reference is populated and parent children are populated, it serializes for ever. Here's a set of test console code to show you

Which data types WCF service can handle ?

别来无恙 提交于 2019-12-11 00:08:50
问题 I am new to WCF. Previously I used WCF service for basic data types like string, int32 etc. But when I try to use BitmapImage class its Test Client giving following error Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata. When I replace BitmapImage with String it works fine. That means I am missing some piece of code. For better understanding here is my code. WCF Interface code using System; using System.Collections

Using WCF DataContract in MVC SessionState using AppFabric cache

帅比萌擦擦* 提交于 2019-12-09 06:30:21
问题 I have a Data Access Layer, a Service Layer, and a Presentation Layer. The Presentation Layer is ASP.NET MVC2 RTM (web), and the Service Layer is WCF (services). It's all .NET 3.5 SP1. The problem is that in the services, the objects being returned are marked with the [DataContract] attribute. The web is using the AppFabric Cache (a.k.a Velocity) SessionStateProvider to store session state. Due to this, anything I store in the session must be serializable. Here comes the problem: the

How do I add an XML attribute using DataContract

喜欢而已 提交于 2019-12-08 14:46:08
问题 I have a simple class I'm serializing. [DataContract(Name = "Test", Namespace = "")] public class Test { [DataMember(Order = 0, Name = "Text")] public string Text { get; set; } public Test() {} } This kicks out the following XML: <Test> <Text>Text here</Text> </Test> What I want is: <Test> <Text type="MyType">Text here</Text> </Test> How do I add attributes the the XML elements? Thanks in advance. 回答1: You can't add attributes to a DataContract. You either have to use a class that Implements

What is the format of the DataContractAttribute.Namespace Property?

依然范特西╮ 提交于 2019-12-08 09:33:15
问题 This MSDN article recommends always to provide a namespace to a ServiceContract and DataContract. Examples usually have a "schema" prefix and a URI type pattern for the namespace such as Namespace="urn:WCFEssentials/Samples/2008/12" instead of a traditional C# namespace with dot-notation such as Namespace="MyNamespace.MyDataClasses" What is the suggested format the namespace property? Do we need the schema prefix? Why is this format suggested? 回答1: It's an XML Namespace. Those can either be

DataContract not available at WCF client service reference

坚强是说给别人听的谎言 提交于 2019-12-08 08:32:39
问题 I have this Data contract in my WCF service [DataContract] public class Department { [DataMember] public List<Section> Sections { get; set; } } [DataContract] public class Section { [DataMember] public List<Room> Rooms { get; set; } } [DataContract] public class Room { [DataMember] public uint RoomId { get; set; } } When I reference my service in client application,I only see Room class,Can any body explain me why contract for Department and Section class are not available at client side. 回答1

ASP.NET MVC 5 - IdentityUser in WCF?

Deadly 提交于 2019-12-08 08:30:12
问题 I am currently writing a WCF service that will use ASP.NET Identity to perform all membership and claims related stuff. (That is, authentication, registration, and all will be performed by calling this WCF) [DataContract(IsReference=true)] public class ApplicationUser: IdentityUser { [DataMember] public string FirstName { get; set; } [DataMember] public string LastName { get; set; } [DataMember] public string Email { get; set; } } The problem is that "IdentityUser" is a class in Microsoft

Nested [DataContract]'s not serialising through WCF

半城伤御伤魂 提交于 2019-12-08 08:06:16
问题 I'm having an issue where a class decorated with the [DataContract] attribute and appropriate [DataMember] attributes on properties is not serialising nested [DataContract] classes. This is the class i'm trying to serialise: [DataContract(Namespace = "http://foo.bar.com.au")] [KnownType(typeof(Point))] [KnownType(typeof(Site))] public sealed class Alarm : IExtensibleDataObject { [DataMember] public Point SourcePoint { get; set; } [DataMember] public Site SourceSite { get; set; } [DataMember]