Problem with the XML returned by web methods
Hi, I have a weird problem with the XML returned from web-method.
I have a class that is auto-generated by a tool. The tool reads a table from the database and generates the class automatically. The "id" field is not supposed to be modified as it is just a representation of the "id" field of the database and is auto incremental.
Let's see the whole problem through a example:
Table in database
Code:
Table A
----------
id : int --auto incremental--
af : nvarchar(30)
bf : nvarchar(30)
The tool generates a class like this:
Code:
public class A{
private int id;
private string af;
private string bf;
public A(string af, string bf)
{
this.af=af;
this.bf=bf;
}
public int Id{
get{
return this.id;
}
}
public string Af{
get{
return this.af;
}
set{
this.af=value;
}
}
public string Bf{
get{
return this.bf;
}
set{
this.bf=value;
}
}
}
I have a web method which uses a "Class Manager" which returns all the objects of a certain class:
Code:
[WebMethod]
public List<A> getAllAs()
{
return AClassManager.getAll();
}
The problem is, that in the XML which is returned by the web method, my objects are expressed in tags as follow:
Code:
<A>
<Af>My a field</Af>
<Bf>My b field</Bf>
</A>
And the "Id" property is missing!!. Doing some research I found out that this is because the "Id" property doesn't have a defined "set method". I defined the set method and I could see the "Id" in the XML. The problem is that I have a lot of classes like this, which are auto-generated, and is a very big problem define manually the "set method".
Is this a Coolite problem or a problem related to "web services" in generall? Who handle the List<A> and generates the XML?
How can I solve this? I really need to use the "Id" property!
Thanks in advance!
Christian.