views:

263

answers:

3

Hi,

If I have custom types (classes) in my web service, do I have to mark with with special attributes so they are serialized properly?

i.e. [SomeAttribute] ?

Update I am using WSE at the moment

+1  A: 

If you are using the Data Contract serializer by default nothing is serialized - this is the opposite of the older XmlSerializer - which is the older asmx web service approach.

For WCF look at the DataContractAttribute for starters: link text

Richard
+1  A: 

You need to mark them with [DataContract] and the member variables that you want to send over the wire with [DataMember] (those attributes live in System.Runtime.Serialization, not in System.ServiceModel).

This will mean that svcutil will generate a client-side proxy class with those matching members. It won't however be the same as passing the actual class (which wouldn't make sense anyway).

EG:

[DataContract]
public class Person
{
    public Person()
    { }

    [DataMember]
    public string Name { get; set; }

    public string ThisMethodNotExposedToWcf() { }
Orion Edwards
what about in WSE?
A: 

The obsolete WSE uses the XmlSerializer. It should serialize most public read/write properties of types that have a default constructor. For more details, look up XmlSerializer.

And convert from WSE to WCF as soon as possible, as WSE is obsolete.

John Saunders