locked
Return Array from web service is empty RRS feed

  • Question

  • Hi,

    I return an array of class from a web service to my client app, but when i check the data return the array has the correct number of elements but no data at all. I have stepped thru the service and it is populated as I would expect, but when passed back to the client nothing.

    any help at all would be much appreciated

    Martin
    Tuesday, March 4, 2008 11:43 AM

Answers

  • I have just answered my own question.

    in the class definition I have left the namespace blank so my class are portable. This seems to cause an issue in return type when returning, specifically, an array of class. In another method I return a single class with no issues.

    anyway I added the namespace of the service and the array returned.
    Tuesday, March 4, 2008 1:29 PM

All replies

  • You have some example?

    Tuesday, March 4, 2008 12:36 PM
  • [System.SerializableAttribute()]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(AnonymousType = false)]
    [System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
    public class Office
    {
        [XmlElement("number")]
        public string of_number;
        [XmlElement("housename")]
        public string of_house_name;
        [XmlElement("street")]
        public string of_street;
        [XmlElement("district")]
        public string of_district;
        [XmlElement("posttown")]
        public string of_town;
        [XmlElement("county")]
        public string of_county;
        [XmlElement("postcode")]
        public string of_postcode;
        [XmlElement("dx_number")]
        public string of_dx_no;
        [XmlElement("dx_exchange")]
        public string of_dx_ex;
        [XmlElement("contact_number")]
        public string of_contact;
    }

    This is an example class i have just used to try a more simple return

    [WebMethod(CacheDuration = 0, MessageName = "arrayTest", Description = "Test")]
        public Office[] RetrieveArray()
        {
    <poulate array then return>
    }


    client call to web method

    private void button1_Click(object sender, EventArgs e)
            {
                Instruction.Office[] r;
                Instruction.instructionService iService = new Instruction.instructionService();
                r = iService.RetrieveArray();
            }

    the return r is empty even tho I initialise 10 array elements with values

    Could this be that I have not added a namespace in the class definition?
    Tuesday, March 4, 2008 1:17 PM
  • I have just answered my own question.

    in the class definition I have left the namespace blank so my class are portable. This seems to cause an issue in return type when returning, specifically, an array of class. In another method I return a single class with no issues.

    anyway I added the namespace of the service and the array returned.
    Tuesday, March 4, 2008 1:29 PM
  • I have also just found that removing the Namespace = "" completely also gives me the same results and makes my classes portable again.
    Tuesday, March 4, 2008 1:33 PM