datacontractserializer

Invalid output with inherit class

谁说胖子不能爱 提交于 2020-01-03 08:55:09
问题 I have 2 classes [DataContract, KnownType(typeof(B))] public class A { [DataMember] public string prop1 { get; set; } [DataMember] public string prop2 { get; set; } [DataMember] public string prop3 { get; set; } } [DataContract] public class B : A { [DataMember] public string prop4 { get; set; } } and the following method: List<B> BList = new List<B>(); BList = new List<B>() { new B() { prop1 = "1", prop2 = "2", prop3 = "3", prop4 = "4" } }; List<A> AList = BList.Cast<A>().ToList();

WCF - serializing inherited types

与世无争的帅哥 提交于 2020-01-03 06:49:11
问题 I have these classes: [DataContract] public class ErrorBase {} [DataContract] public class FileMissingError: ErrorBase {} [DataContract] public class ResponseFileInquiry { [DataMember] public List<ErrorBase> errors {get;set;}; } An instance of the class ResponseFileInquiry is what my service method returns to the client. Now, if I fill ResponseFileInquiry.errors with instances of ErrorBase, everything works fine, but if I add an instance of inherited type FileMissingError, I get a service

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,

How to deserialize a WCF soap response message from a file with DataContractSerializer?

谁说我不能喝 提交于 2020-01-02 01:10:13
问题 When I call a web service operation, WCF deserializes the message to the proxy class with the DataContractSerializer: why couldn't I do the same ? Here is the soap message in the file ActLoginResponse.xml: <SOAP-ENV:Envelope xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="urn:PlotiIntf" xmlns:ns2="urn:PlotiIntf-IPloti" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema

Is there a way to override how DataContractJsonSerializer serializes Dates?

烈酒焚心 提交于 2020-01-02 00:49:08
问题 Is there a way to change how the DataContractJsonSerializer serializes dates? Currently, it'll convert a date to something like: { "date": "/Date(1260597600000-0600)/" } I would rather have it serialize as just the milliseconds since utc 1970. That way, other languages can easily work with the json data. 回答1: No, there's no hook in the serializer itself to do that. But you can use some of the serialization callbacks to implement this same behavior. You'd create another data member (of type

MS JSON date serialization and daylight saving time

前提是你 提交于 2020-01-01 16:51:29
问题 We have an Ajax web service hosted in an ASP.NET application. This service accepts a DateTime parameter which, for the purposes of this question, should receive the DateTime equivalent of /Date(1359727200000-0200)/ , which is a MS-JSON literal for Feb 1, 2013 9:00 AM in Brazil time. This literal is what the browser sends within the Ajax request. But instead of receiving that date and time, the argument passed to the service method is Feb 1, 2013 12:00 PM . To make matters worse, the argument

MS JSON date serialization and daylight saving time

自闭症网瘾萝莉.ら 提交于 2020-01-01 16:51:06
问题 We have an Ajax web service hosted in an ASP.NET application. This service accepts a DateTime parameter which, for the purposes of this question, should receive the DateTime equivalent of /Date(1359727200000-0200)/ , which is a MS-JSON literal for Feb 1, 2013 9:00 AM in Brazil time. This literal is what the browser sends within the Ajax request. But instead of receiving that date and time, the argument passed to the service method is Feb 1, 2013 12:00 PM . To make matters worse, the argument

Can I force svcutil.exe to generate data contracts for a WCF service?

北慕城南 提交于 2020-01-01 10:07:57
问题 I would like to force svcutil to generate all data contracts in an assembly that is used by WCF, regardless of whether or not a type is referenced by a given operation contract. [DataContract] public class Foo { } [DataContract] public class Bar : Foo { } [ServiceContract] public interface IService { [OperationContract] void Get(Foo foo); } Given this setup I cannot get svcutil to generate a version of Bar as there are no operation contracts that currently reference it. Is there a way to

Can I force svcutil.exe to generate data contracts for a WCF service?

陌路散爱 提交于 2020-01-01 10:07:13
问题 I would like to force svcutil to generate all data contracts in an assembly that is used by WCF, regardless of whether or not a type is referenced by a given operation contract. [DataContract] public class Foo { } [DataContract] public class Bar : Foo { } [ServiceContract] public interface IService { [OperationContract] void Get(Foo foo); } Given this setup I cannot get svcutil to generate a version of Bar as there are no operation contracts that currently reference it. Is there a way to