datacontract

WCF DataContracts

南笙酒味 提交于 2020-01-10 10:34:09
问题 I have a WCF service hosted for internal clients - we have control of all the clients. We will therefore be using a data contracts library to negate the need for proxy generation. I would like to use some readonly properties and have some datacontracts without default constructors. Thanks for your help... 回答1: Readonly properties are fine as long as you mark the (non-readonly) field as the [DataMember], not the property. Unlike XmlSerializer, IIRC DataContractSerializer doesn't use the

Datacontract serialization error

醉酒当歌 提交于 2020-01-07 03:04:11
问题 This is the continuation of How to set [DataMember] on all class members So I have to serialize a class with dictionaries and other members. I have chonse the datacontext serialization that se public SimpleDataGridSample() { if (false) { MyClass theclass = new MyClass(); var serializer = new DataContractSerializer(typeof(MyClass)); using (Stream fileStream = File.Open("aaa.bin", FileMode.Create)) { XmlDictionaryWriter binaryDictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(fileStream)

linq issue with creating relationships

余生颓废 提交于 2020-01-05 12:35:01
问题 Seems I have a slight problem with my linq, I have a datacontract for Groups and I have a seperate datacontract for messages. Messages can be part of a Group. However when I update a message record its not reflected when I list the group information, the message is still the same for that group. But yet the update is reflected when I directly list messages? This is how I add a message to a group: //lists for reference: List<Group> Groups = new List<Group>(); List<Message> messages = new List

WCF An error occurred while receiving the HTTP response

▼魔方 西西 提交于 2020-01-05 12:08:59
问题 Here's what my WCF service should be returning. When I command PaymentData out of ResponseModel and add other DataMembers in that class it works. [DataContract] public class ResponseModel { [DataMember] public PaymentData PaymentData { get; set; } } Here's the PaymentData class: [DataContract] public class PaymentData { [DataMember] public PaymentType PaymentType { get; set; } [DataMember] public string CardNumber { get; set; } [DataMember] public DateTime ExpirationDate { get; set; } ///

Is there any way to hide/flatten base types in WCF service data contracts?

心已入冬 提交于 2020-01-04 19:06:34
问题 Consider the following simple example: [DataContract("{0}Base")] public class Base<T> where T : Entity<T> { // Common methods & properties. No WCF exposed properties } [DataContract] public class Employee : Base<Employee> { // WCF exposed properties } The base class Base has no properties of interest to the WCF service consumers, but WCF forces me to also annotate the Base class with a [DataContract] attribute. This essentially shows up on the service client as Employee : EmployeeBase with

Is there any way to hide/flatten base types in WCF service data contracts?

纵饮孤独 提交于 2020-01-04 19:06:18
问题 Consider the following simple example: [DataContract("{0}Base")] public class Base<T> where T : Entity<T> { // Common methods & properties. No WCF exposed properties } [DataContract] public class Employee : Base<Employee> { // WCF exposed properties } The base class Base has no properties of interest to the WCF service consumers, but WCF forces me to also annotate the Base class with a [DataContract] attribute. This essentially shows up on the service client as Employee : EmployeeBase with

How to serialize class that derives from class decorated with DataContract(IsReference=true)?

筅森魡賤 提交于 2020-01-04 05:13:52
问题 I have class A that derives from System.Data.Objects.DataClasses.EntityObject . When I try to serialize using var a = new A(); DataContractJsonSerializer serializer = new DataContractJsonSerializer(a.GetType()); serializer.WriteObject(Response.OutputStream, a); I get error TestController+A._Id' is not marked with OptionalFieldAttribute, thus indicating that it must be serialized. However, 'TestController+A' derives from a class marked with DataContractAttribute and an IsReference setting of

Adding a DataMember to a different namespace to the DataContract

て烟熏妆下的殇ゞ 提交于 2020-01-02 08:26:30
问题 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 ? 回答1: You can define subdatacontracts in different namespaces and use them as members of another datacontract,

Adding a DataMember to a different namespace to the DataContract

自作多情 提交于 2020-01-02 08:25:41
问题 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 ? 回答1: You can define subdatacontracts in different namespaces and use them as members of another datacontract,

WCF DataContract - marking member IsRequired=false

青春壹個敷衍的年華 提交于 2020-01-02 05:22:07
问题 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