datamember

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

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 - convert empty element to nullable native type

做~自己de王妃 提交于 2019-12-05 01:38:14
问题 Leaving a SOAP field element empty results in a cast error for native types. (sadly cannot use xsi:nil="true" due to client constraints) Marking the WCF contract native type as nullable<> does not appear to be enough to stop the following error being returned to the client. The string '' is not a valid Boolean value. at System.Xml.XmlConvert.ToBoolean(String s) at System.Xml.XmlConverter.ToBoolean(String value) System.FormatException does anyone know the best method of instructing the

WCF web service Data Members defaulting to null

筅森魡賤 提交于 2019-12-04 20:35:12
I am new to WCF and created a simple REST service to accept an order object (series of strings from XML file), insert that data into a database, and then return an order object that contains the results. To test the service I created a small web project and send over a stream created from an xml doc. The problem is that even though all of the items in the xml doc get placed into the stream, the service is nullifying some of them when it receives the data. For example lineItemId will have a value but shipment status will show null. I step through the xml creation and verify that all the values

WCF DataMember EmitDefaultValue on value type? (but set my own default value)

爷,独闯天下 提交于 2019-12-04 04:55:25
问题 I have the following: [DataContract] public class Foo { [DataMember(EmitDefaultValue = true) public bool Bar { get; set; } } 2 Questions: What really happens here because my bool can't really be null, so if I emit the default value then what? How do I make it so that if someone passes a message without the Bar part then it my server sets it to true instead of false by default? Basically, my bar member is not required to be transmitted over the soap message and if it isn't I want it to default

What does it mean to put DataMemberAttribute on interface member?

孤街浪徒 提交于 2019-12-04 04:40:49
What does it mean to put a DataMemberAttribute on an interface member? How does this affect derived classes? As shown in the following signature, the DataMember attribute is not inheritable [AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field, Inherited = false, AllowMultiple = false)] public sealed class DataMemberAttribute : Attribute Therefore, it makes very little sense to decorate interface members with this attribute as you will have to decorate the implementing classes' members with this attribute too. In my case, I use this attributes with my WCF services. When I

WCF - convert empty element to nullable native type

久未见 提交于 2019-12-03 16:59:50
Leaving a SOAP field element empty results in a cast error for native types. (sadly cannot use xsi:nil="true" due to client constraints) Marking the WCF contract native type as nullable<> does not appear to be enough to stop the following error being returned to the client. The string '' is not a valid Boolean value. at System.Xml.XmlConvert.ToBoolean(String s) at System.Xml.XmlConverter.ToBoolean(String value) System.FormatException does anyone know the best method of instructing the DataContractSerializer to convert empty elements to be deserialized to null? My example WCF service contract;

WCF DataMember EmitDefaultValue on value type? (but set my own default value)

假装没事ソ 提交于 2019-12-02 01:52:19
I have the following: [DataContract] public class Foo { [DataMember(EmitDefaultValue = true) public bool Bar { get; set; } } 2 Questions: What really happens here because my bool can't really be null, so if I emit the default value then what? How do I make it so that if someone passes a message without the Bar part then it my server sets it to true instead of false by default? Basically, my bar member is not required to be transmitted over the soap message and if it isn't I want it to default to true, not false. I'm not sure of the proper combination to make my message sizes efficient (cut out

Data member default values, how to figure out whether something was really sent?

拈花ヽ惹草 提交于 2019-12-02 01:33:28
By default, WCF deserializes missing elements into default values like null, 0 or false. The problem with this approach is that if it's a basic type like number 0 I'm not sure whether it means the real value sent by an external system or a default value generated by WCF. So my question is: Is it possible to find out at run-time whether the default value means "I didn't send anything". This is crucial because we can't update and overwrite existing data in the database with the default values just because the external system didn't send a particular element this time (data corruption). Microsoft

Serialization DataMember (name) override issue

大兔子大兔子 提交于 2019-12-01 15:16:22
I am using a DataContractJsonSerializer and have an issue with the DataMember Name. I made a base class and several derived classes. I need the derived classes because I have different json strings. I want to deserialize the json strings and therefore need different names for the datamembers. I try to change the DataMember name as in the following example: Baseclass: [DataContract] public abstract class BaseClass { [DataMember] public virtual string FirstMethod { get; protected set; } } Derived class: [DataContract] [KnownType(typeof(BaseAccess))] public class DerivedClass { [DataMember(Name=