datacontract

can we convert Odata metadata to C# code (datacontract)

感情迁移 提交于 2019-12-25 05:38:08
问题 there is a odata webservice, i can get metadata from http://service-uri.com/$metadata which contains definition of all its model object, is there any tools that i can use, to convert that metadata xml to data contract class in C#? 回答1: The WCF Data Services Client library can generate C# classes for you from the $metadata endpoint. These classes won't have the [DataContract] attribute, but you can use them with the rest of the client library to interact with the service. To use this feature,

Passing an inherited “Data Contract” through WCF call?

家住魔仙堡 提交于 2019-12-25 01:34:23
问题 One of my WCF endpoints has this method: GetData(DataTable dt) I tried to create a class on the client that inherits from the DataTable class public class ExtendedDataTable : DataTable{ //...implementation } and pass it along with the endpoint call: GetData(new ExtendedDataTable()); Then I got the SerializationException . Accordingly to the error, it suggests that I use either DataContractResolver or the KnownType attribute. I don't want to use the KnownType, because I shouldn't have to

How to serialize nullable DateTime in a WCF DataContract?

大憨熊 提交于 2019-12-24 12:42:06
问题 I am having trouble serializing this thing. namespace Such.Namespace.Wow { [DataContract(Namespace = "http://very.namespace.uh")] public class DogeResponse { [DataMember] public virtual int Foo { get; set; } [DataMember] public virtual DateTime? ExpiringDate { get; set; } } } In generated WSDL : <xs:complexType name="DogeResponse"> <xs:sequence> <xs:element minOccurs="0" name="Foo" type="xs:int"/> <xs:element minOccurs="0" name="ExpiringDate" nillable="true" type="xs:dateTime"/> </xs:sequence

datacontractserializer deserialize list<> always empty

此生再无相见时 提交于 2019-12-24 08:50:04
问题 I'm deserializing data received from a web-service. The problem is that the deserialization of List returns an empty list and no exception are generated. Can you help me figure out why? We have tried several possible syntax. The code below is the closest to the correct solution but we cannot deserialize correctly as a list of classes. <ArrayOfBatch xmlns="http://schemas.datacontract.org/2004/07/myns" xmlns:i="http://www.w3.org/2001/XMLSchema-instance"> <MaasBatch> <BatchName>All Users<

Are there any other reasons why I should consider omitting emitting the default value to be a bad practice?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-23 12:07:05
问题 I've worked with WCF for awhile now and in places where both client and server tend to be co-released; that is, new versions have almost always been released at the same time. Interoperability and versioning aren't issues (in this case at least). The MSDN documentation, DataMemberAttribute.EmitDefaultValue and Data Contract Versioning, suggests it is a bad practice to emit the default value unless there is a specific need and to support versioning. In practice, I've found it useful and at

Mark deprecated fields in WCF contract

余生长醉 提交于 2019-12-23 08:49:38
问题 I have a wcf contract that works with client v1. Now I'm working on service v2, and i want to mark some of the fields as deprecated, So client v1 will see and use them, and client v2 will ignore them. Are there any best practices for this issue? Are there any existing attributes in WCF that i should use? thanks. 回答1: You can decorate your old properties as [Obsolete] but the client will only see them if they use a DLL reference and not service/web reference (WSDL). [Obsolete] decoration will

WCF Data Contract / Serialization

流过昼夜 提交于 2019-12-22 08:37:14
问题 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? 回答1: POCO support have been introduced in WCF since

Does the compact framework 3.5 support System.Runtime.Serialization?

孤街浪徒 提交于 2019-12-22 08:20:04
问题 I am writing a library which is a set of classes meant to be shared between many different .NET applications, including at least one which uses the .NET compact framework. I have been making these classes use the [DataContract] attribute with a bunch of [DataMember]s so that they are easy to serialize and deserialize using the DataContractJSONSerializer. I have been searching the web to try to find out if this functionality (DataContractAttribute, DataMemberAttribute, and

Entity Framework POCO with WCF software design question

大城市里の小女人 提交于 2019-12-21 18:31:53
问题 I am going to use Entity Framework and WCF in my application. The suggested practice, as I saw, is using POCO with Entity Framework and also using POCO classes as DataContracts. That is actually what POCO and Attributes are used for, -if I am not wrong. However I am asked to use seperate classses for Entity Framework POCO's and WCF DataContracts. And to use a mapper between POCO's and DataContracts. Like, Foo and FooContract with same properties. I am on the first approachs side but I wonder

What does it mean to put DataMemberAttribute on interface member?

这一生的挚爱 提交于 2019-12-21 09:29:24
问题 What does it mean to put a DataMemberAttribute on an interface member? How does this affect derived classes? 回答1: 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