Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't a DataMember in WCF return Type?

Tags:

wcf

Trying to get this to work, with no luck:

[DataMember]
public Type ParameterType { get; set;}
like image 562
AKoran Avatar asked Jul 10 '09 17:07

AKoran


People also ask

What does DataMember attribute do?

Gets or sets a value that specifies whether to serialize the default value for a field or property being serialized.

What is the use of DataMember in C#?

Data Member are the fields or properties of your Data Contract class. You must specify [DataMember] attribute on the property or the field of your Data Contract class to identify it as a Data Member. DataContractSerializer will serialize only those members, which are annotated by [DataMemeber] attribute.

What is the KnownType attribute in WCF?

The KnownTypeAttribute class allows you to specify, in advance, the types that should be included for consideration during deserialization.

What is data contract and DataMember in C#?

DataContact. A datacontract is a formal agreement between a client and service that abstractly describes the data to be exchanged. In WCF, the most common way of serialization is to make the type with the datacontract attribute and each member as datamember. Creating a basic DataContract and DataMember.


2 Answers

Web Services, in general, are meant to be cross-platform. What would a Java program do with a System.Type from .NET?

Also, what part of Type would you like to see serialized, and how would you like to see it deserialized?

like image 180
John Saunders Avatar answered Sep 20 '22 00:09

John Saunders


Any field or property that returns System.Type is not serializable using WCF because, at runtime, the actual type of the object is System.RuntimeType, which is marked as internal, and thus cannot be automatically serialized by the DataContractSerializer, which can only serialize publicly accessible types.

However, you could write an IXmlSerializer wrapper around System.Type that will pull out the information you intend to transfer.

like image 22
Marcus Griep Avatar answered Sep 21 '22 00:09

Marcus Griep