views:

26

answers:

1

Hey guys,

I want to transfer some data classes via Webservice:

public class MyClass
{
    public int Int { get; set; }

    public MyClass(int v)
    {
        Int = v;
    }

    private MyClass()
    {

    }
}

public enum MyEnum
{
    One = 7,
    Two = 13,
    Three = 15
}

public class TestDataClass
{
    private int _someInt;

    public List<MyClass> Values { get; set; }

    public int SomeInt
    {
        get
        {
            return _someInt + 10;
        }

        set { _someInt = value; }
    }

    public TestDataClass(int someInt)
    {
        SomeInt = someInt;

        Values = new List<MyClass>();
        for (int i = 0; i < 10; i++)
        {
            Values.Add(new MyClass(i));
        }

    }

    private TestDataClass() {}
}

TestDataClass is the class beening passed, what should be attributed with serializable?

Thanks, Alex.

A: 

If you want to use the (old) ASMX style webservice: Yes.

When using WCF: No, use [DataContract] instead.

In both cases, you need attributes for the main class and for any embedded type that is not already Serializable or a 'known type'.

Henk Holterman
But the class above gets passed just fine without the attribute
Arjor
If it runs, then it's OK. If you use something non-serializable you will get an error (runtime)
Henk Holterman