datacontract

What is the format of the DataContractAttribute.Namespace Property?

烂漫一生 提交于 2019-12-06 20:52:35
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? It's an XML Namespace . Those can either be in the urn: format or they can be URLs. Here are some additional suggestions from MSDN : The namespace can

C# DataContract Attribute for Private Fields?

戏子无情 提交于 2019-12-06 06:25:44
For a class marked with the attribute, [DataContract], does its private fields, which should be serialized, be marked as [DataMember]? Example: [DataContract] public class Component { // [DataMember] is not needed since public fields get automatically serialized public int number; // do I need [DataMember] here? private string characters; // [DataMember] is required here, but I also need to include the // attribute [DataMember] in this class's definition private complexType cT; I'm reading DataContractAttribute Class correctly, right? No, it doesn't look like you are reading the documentation

Serialization / Derialization of a tree structure

↘锁芯ラ 提交于 2019-12-06 03:29:43
问题 I'm trying to figure out the best way to save (serialize) and later open (deserialize) a tree structure. My structure is made up of various object types with different properties, but each inherits from a base abstract "Node" class. Each node has unique ID (GUID), and has an AddSuperNode(Node nd) method that will set the parent of a node. This in turn calls other methods that allow the parent node to know what sub nodes it has. However, some nodes also utilize a AddAuxSuperNode() method that

Adding a DataMember to a different namespace to the DataContract

邮差的信 提交于 2019-12-06 03:03:29
With the XmlSerializer I can have my members in different namespaces to the parent type. Can I do the same thing with DataContractSerializer ? I would like the following XML: <h:Type xmlns:h="http://schemas.e.com/WebServices" xmlns="http://schemas.e.com/WebServices"> <Member xmlns="http://schemas.e.com/CoreTypes">0</Member> </h:Type> Is this possible in with DataContractSerializer ? nitzmahone You can define subdatacontracts in different namespaces and use them as members of another datacontract, but you can't control the individual member names and/or shapes. The DataContractSerializer isn't

WCF: How to construct DataContracts for a type within a type

☆樱花仙子☆ 提交于 2019-12-05 14:46:51
I have a wcf service which exposes a function that returns a complex type as its return type. This response type in turn contains another complex object defined by me. I am looking at creating data contracts for my WCF and am wondering how this is supposed to be done. I currently have this (some properties removed for ease of reading): The Function ///<summary> /// Interface to describe a cluster query WCF service. ///</summary> [ServiceContract] public interface IClusterQueryWcfService { /// <summary> /// A method to retrieve the name of the necessary cluster table for a given zoom level,

Why am I using the KnownType attribute wrong?

本秂侑毒 提交于 2019-12-05 14:39:19
I am trying to deserialize a json response from a google api, so i thought i would define a couple classes to help with it: [DataContract] public class DetectionResult:ResponseData { [DataMember(Name="language")] public string Language { get; set; } [DataMember(Name="isReliable")] public bool IsReliable { get; set; } [DataMember(Name="confidence")] public double Confidence {get;set;} } [DataContract] public abstract class ResponseData { [DataMember(Name = "error")] public TranslationError Error { get; set; } } [DataContract] public class TranslationError { [DataMember(Name="code")] public int

WCF Data Contract / Serialization

二次信任 提交于 2019-12-05 13:38:05
I created a simple WCF application which expose one operation. This operation takes a composite data type as parameter. I have not decorated this composite data type with [DataContract] attribute. But this is working and I can see the Schema for this in WSDL. Now my understanding is that this new custom type should be decorated with [Serializable] or [dataContract] attribute to take part in the Web services operation. What I am missing here? POCO support have been introduced in WCF since .NET 3.5 SP1 and you no longer need to decorate your objects with [DataContract] and [DataMember]

Can I prevent a specific datamember from being deserialized?

喜欢而已 提交于 2019-12-05 11:17:09
I have a datacontract like this [DataContract] class MyDC { [DataMember] public string DM1; [DataMember] public string DM2; [DataMember] public string DM3; } and sometimes I want to prevent DM2 from being deserialized when being returned from an OperationContract. Something like this: [OperationContact] public MyDC GetMyDC() { MyDC mdc = new MyDC(); if (condition) { // Code to prevent DM2 from being deserialized } return mdc; } I could always make a new DataContract that has only DM1 and DM3 and generate that from the MyDC instance but I want to see if it is possible to programatically remove

WCF DataContract - marking member IsRequired=false

自古美人都是妖i 提交于 2019-12-05 10:02:13
I have a contract as follows: [DataContract] public class MyObj { [DataMember(IsRequired=true)] public string StrA {get; private set;} [DataMember(IsRequired=false)] public string StrB {get; private set;} } What exactly does IsRequired mean? Does IsRequired=false mean that I can pass an instance of MyObj across the wire with StrB unitialized or does it mean that I can pass an instance of MyObj across the wire with StrB absent? If the latter, how do I actually instantiate + send across an instance of MyObj without StrB ? DataMember 's IsRequired tells the serialization engine whether the value

Including XML Comments in DataContract Serializer Metadata

回眸只為那壹抹淺笑 提交于 2019-12-05 06:07:01
is there some way of sending the summary info of properties in a DataContract? e.g. [DataContract] public class MyClass { /// <summary> /// My Summary information /// </summary> [DataMember] public int MyProperty {get;set;} } can this be available to the client that gets the datacontract? I doubt it, just hoping somebody knows something I don't, which is quite likely. :) Take a look at WCFExtras on CodePlex. I haven't used it, but it sounds like it does exactly what you want: Adding WSDL Documentation from Source Code XML Comments This extension allows you to add WSDL documentation (annotaiton