views:

355

answers:

4

I have these classes:

public abstract class CustomField
{
    public String Id { get; set; }
    public String Name { get; set; }
    public String Description { get; set; }
    public FieldType Type { get; set; } 

    public enum FieldType
    { 
        String = 0,
        Integer = 1,
        Boolean = 2,
        List = 3
    }
}

public class StringCustomField:CustomField
{
    public String Value { get; set; }
    public Int32 MinLenght { get; set; }
    public Int32 MaxLenght { get; set; }

    public StringCustomField()
    {
        this.Type = FieldType.String;
    }
}

public class CustomGroup
{
    public String Id { get; set; }
    public String Name { get; set; }
    public String Description { get; set; }
    public List<CustomField> FieldList = new List<CustomField>();
}

When I try to transfer CustomGroup through my webservice I get this error:

The remote server returned an error: NotFound

Serialization is failing when C# tries to transfer my StringField through my CustomField.

What am I doing wrong?

Marc Gravel tell me to do that and i understand the solution but some thing is wrong, no effects, cath the same error!! , help!!

[XmlInclude(typeof(StringCustomField))]
[XmlInclude(typeof(IntegerCustomField))]
[XmlInclude(typeof(BooleanCustomField))]
[XmlInclude(typeof(ListCustomField))]
public abstract class CustomField
{
    public String Id { get; set; }
    public String Name { get; set; }
    public String Description { get; set; }
    public FieldType Type { get; set; } 

    public enum FieldType
    { 
        String = 0,
        Integer = 1,
        Boolean = 2,
        List = 3
    }
}
+1  A: 

List<CustomField> will serialize and deserialize to a CustomField[] if you're using a web service, won't it?

David M
+1  A: 

use

public class CustomGroup
{
    public String Id { get; set; }
    public String Name { get; set; }
    public String Description { get; set; }
    public List<CustomField> FieldList = new List< StringCustomField >();

}

instead

Edwin Tai
It's not clear to me that this is at all semantically correct. Perhaps there are other derived classes that we don't know about (seems likely) that would be included in the FieldList.
tvanfosson
Yes more tree!! BooleanCustomField, IntegerCustomField, ListCustomField!!! The sample above solve my problem for only one derived class!!
CrazyJoe
That isn't valid in any version of .NET, including 4.0
Marc Gravell
+1  A: 

If you are sending subclasses as xml, you will need [XmlInclude]:

[XmlInclude(typeof(StringCustomField))]
public abstract class CustomField
{...}

You can add multiple [XmlInclude(...)] markers for any other subclasses in the model.

Marc Gravell
Marc i include the markers but cat same error? any idea?
CrazyJoe
Marc something change im my scenary when i recompile the solution and try to update de service reference on client side i catch an error talking about System.Xml not found, now if i solve this!!XD
CrazyJoe
If you get the same error, why mark as answered? I don't know what the System.Xml thing is without looking.
Marc Gravell
A: 

If i understand you correctly, you should 1. connect your web service to your app 2. use the namespace of the WS, so all the classes will be used from the Proxy i don't think that the local class will be understood by the remote web serivce correctly, even if you're using the same assembly on both parties

ifesdjeen
the objects is wornking on both sides, there is no problem to me!!Marc Gravell get my problem!! I try the solution now!! thanks opetrov!!
CrazyJoe