Questions tagged [datamember]

204 questions
8
votes
3 answers

DataMember attributes for Data validation

I am looking to place attributes on my WCF data contract members to validate string length and possibly use regex for more granular parameter validation. I can the [Range] attribute for numeric and DateTime values and was wondering if any of you…
Jessica
  • 101
  • 1
  • 1
  • 3
8
votes
6 answers

Accessing different data members belonging to the same object from 2 different thread in C++

I have a few objects I need to perform actions on from different threads in c++. I known it is necessary to lock any variable that may be used by more than one thread at the same time, but what if each thread is accessing (writing to) a different…
7
votes
3 answers

WCF DataMember attribute for read-only fields?

I am trying to create a class with a read-only Id field, however I am having problems retaining the value when the object passes through the WCF server. I cannot set the [DataMember] attribute on the public property since there is no set method, and…
Rachel
  • 130,264
  • 66
  • 304
  • 490
6
votes
2 answers

.NET base type cannot be serialized by WCF

I'm writing a WCF service and want to expose some custom configuration elements (e.g. Custom ConfigurationSection and ConnectionStringSettings) so that I can modify the service's configuration. One of my custom configuration elements inherits from…
6
votes
2 answers

Compile-time re-arrangement of data members?

I was wondering about a possible way to make memory layout of a class to be more effective in templated code. As far as I know, Standard mandates data members of a class to be laid out in memory on order of their declaration. There might be possible…
lapk
  • 3,838
  • 1
  • 23
  • 28
5
votes
1 answer

Custom DataMember names to deserialize a JSON class

I cannot manage to specify custom names for properties. I receive some JSON from the server (which I cannot change) with some ugly property names. I'd like the C# code to stick to naming conventions. Below is the code I have (result0.StringValue…
Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
5
votes
2 answers

DataMember Emit Default Value

I have a .Net Web Service function that can accept one string. That function will then serialize that string to JSON, but I only want to serialize it if it's value is not "". I found these…
RedEagle
  • 4,418
  • 9
  • 41
  • 64
5
votes
4 answers

Can I prevent a specific datamember from being deserialized?

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…
floatingfrisbee
  • 928
  • 1
  • 10
  • 28
5
votes
0 answers

DataMember property 'relation key' cannot be found on the DataSource

I currently have a DataSet that has several tables in it for a C# Windows app. I have one parent table and all of the other tables in this set are child tables that have a relation to the ID column in the parent. I just recently added a new table…
5
votes
1 answer

WCF Read DataMember Name attribute

I have a very simple class called person. public class Person{ [DataMember(Name="MyName")] public string Name { get;set;} } If I try to serialize or de-serialize, everything works great. In the XML I can see a tag called "MyName" and in the…
Raffaeu
  • 541
  • 1
  • 3
  • 9
5
votes
1 answer

WCF - convert empty element to nullable native type

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…
Microsoft Developer
  • 1,919
  • 1
  • 20
  • 27
5
votes
5 answers

ID data member in c++ class

My teacher required us to create ID data member that's generated automatically, and once established it can’t be modified. What is the most appropriate type? if the answer is static const int ID; How can I generate it automatically while it's…
Nora
  • 167
  • 2
  • 3
  • 14
4
votes
3 answers

DataMember vs DataMemberAttribute

[DataContract] public class SearchResults { [DataMember] public List PList { get; set; } [DataMemberAttribute] public int Count { get; set; } } The metadata for DataMember and DataMemberAttribute are same. Is…
VoodooChild
  • 9,776
  • 8
  • 66
  • 99
4
votes
1 answer

Web.Api deserialization fail for model parameter with different name

I've got one method, which take a model [AccountLinkRequest] as a parameter with url-encoded data. It's uses Json.NET by default, and also, I can't use the setting UseDataContractJsonSerializer = true cause I have generic output response model (in…
EvgeniyK
  • 377
  • 3
  • 12
4
votes
3 answers

WCF - Sub-class added to a [DataMember] List causes exception

One of my [DataContract] classes contains a [DataMember] which is a List. BaseClass has a few different sub-classes. Whenever that List contains instances of any sub-class, an exception occurs during/after the Service is returning to the request…
Dan
1
2
3
13 14