Problem with the XML returned by web methods

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    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
    Table A
    ----------
    id : int --auto incremental--
    af : nvarchar(30)
    bf : nvarchar(30)
    The tool generates a class like this:

    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:

    [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:

    <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.
  2. #2

    Resolved!

    Quote Originally Posted by csn View Post
    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
    Table A
    ----------
    id : int --auto incremental--
    af : nvarchar(30)
    bf : nvarchar(30)
    The tool generates a class like this:

    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:

    [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:

    <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.
    People, I posted the same question in the asp forums and I obtained an answer.
    I would like to share it with all of you, check here -> http://forums.asp.net/p/1607452/4102675.aspx

    Regards,

    Christian.

Similar Threads

  1. Replies: 1
    Last Post: Jun 28, 2011, 10:38 PM
  2. Replies: 5
    Last Post: May 05, 2011, 7:05 PM
  3. Replies: 3
    Last Post: Mar 23, 2011, 5:38 PM
  4. Problem calling methods
    By Argons in forum 1.x Help
    Replies: 5
    Last Post: Aug 03, 2009, 2:04 AM
  5. Run script returned from AjaxMethod
    By jchau in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jan 13, 2009, 12:14 PM

Tags for this Thread

Posting Permissions