I am trying to pass nested class to webservice and i get the following error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khushboosoni
    New Member
    • Jun 2010
    • 7

    I am trying to pass nested class to webservice and i get the following error

    The error is "There was an error generating the XML document.". I think there is no need to serialize a class before sending it to a webservice.But im not sure of nested classes.Please give me some solution.

    Here is my class:

    Code:
    public class StudentDO
        {
            private int _iStudentKey;        
            private string _strStudentName;
            private string _strSchoolName;
            private string _strDistrictName;
            private bool _bIsStudentActive;
            private bool _bIsSpecialED;
            .
            .
            .
            private Object[][] _objStudentScores; 
    
                    public StudentDO()
            {
                this._iStudentKey = 0;
                this._strStudentName = string.Empty;
                this._strSchoolName = string.Empty;
                this._strDistrictName = string.Empty;
                this._bIsStudentActive = false;
                this._bIsSpecialED = false;
                this._bIsEnglishLearner = false;
                this._objStudentScores = new Object[10][];
            }
    
            public int StudentKey
            {
                get { return this._iStudentKey; }
                set { this._iStudentKey = value; }
            }
            .
            .
            .
    
            public Object[][] StudentScores
            {
                get { return this._objStudentScores; }
                set { this._objStudentScores = value; }
            }
        }
    }
    The inner class is :
    Code:
        public class StudentScoresDO
        {
          private bool _bIsScoreExists;
          private bool _bIsScoringCompleted;        
          private bool _bIsScoresEnteredByAnotherTeacher;
          private int _iTeacherKey;
          private string _strTeacherName;
          private string _strComments;
          private Object[][] _objItemScores;
        }
    Last edited by Niheel; Jul 23 '10, 07:45 AM. Reason: added code tags to code
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    Is it java?

    Comment

    • khushboosoni
      New Member
      • Jun 2010
      • 7

      #3
      Originally posted by newb16
      Is it java?
      No it is in C#

      Comment

      • Joseph Martell
        Recognized Expert New Member
        • Jan 2010
        • 198

        #4
        Can you show us the code where the exception is actually thrown?

        Also, what version of the .Net framework are you using?

        Comment

        • khushboosoni
          New Member
          • Jun 2010
          • 7

          #5
          The complete details of the exception is:

          System.InvalidO perationExcepti on: There was an error generating the XML document. ---> System.InvalidO perationExcepti on: The type Com.SchoolCity. ReportCards.Rep ortCardLibrary. Data.StudentSco resDO was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
          at System.Xml.Seri alization.XmlSe rializationWrit er.WriteTypedPr imitive(String name, String ns, Object o, Boolean xsiType)
          at Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriter1.Write 1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
          at Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriter1.Write 4_StudentDO(Str ing n, String ns, StudentDO o, Boolean isNullable, Boolean needType)
          at Microsoft.Xml.S erialization.Ge neratedAssembly .XmlSerializati onWriter1.Write 7_ArrayOfStuden tDO(Object o)
          at Microsoft.Xml.S erialization.Ge neratedAssembly .ListOfStudentD OSerializer.Ser ialize(Object objectToSeriali ze, XmlSerializatio nWriter writer)
          at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter, Object o, XmlSerializerNa mespaces namespaces, String encodingStyle, String id)
          --- End of inner exception stack trace ---
          at System.Xml.Seri alization.XmlSe rializer.Serial ize(XmlWriter xmlWriter, Object o, XmlSerializerNa mespaces namespaces, String encodingStyle, String id)
          at System.Xml.Seri alization.XmlSe rializer.Serial ize(TextWriter textWriter, Object o, XmlSerializerNa mespaces namespaces)
          at System.Xml.Seri alization.XmlSe rializer.Serial ize(TextWriter textWriter, Object o)
          at System.Web.Serv ices.Protocols. XmlReturnWriter .Write(HttpResp onse response, Stream outputStream, Object returnValue)
          at System.Web.Serv ices.Protocols. HttpServerProto col.WriteReturn s(Object[] returnValues, Stream outputStream)
          at System.Web.Serv ices.Protocols. WebServiceHandl er.WriteReturns (Object[] returnValues)
          at System.Web.Serv ices.Protocols. WebServiceHandl er.Invoke()


          And the code behind is as follows:

          Code:
          public List<StudentDO> GetStudentsForReportCard(int iTeacherKey, int iLocationKey, string strGrade, string strSchoolYear, int iClassKey)
                  {
                      List<StudentDO> lstStudent = new List<StudentDO>();
          
                      DataSet dsStudentsDetails = GetStudents(iTeacherKey, iLocationKey, strGrade, strSchoolYear, iClassKey);
                      if (!CommonUtility.IsValidObject(dsStudentsDetails)) return null;
                      foreach (DataRow dr in dsStudentsDetails.Tables[0].Rows)
                      {
                          StudentDO objStudent = new StudentDO();
                          objStudent.StudentKey = Convert.ToInt32(dr["Student_Key"]);
                          objStudent.StudentName = dr["Student_Name"].ToString();
                          objStudent.DistrictName = dr["District_Name"].ToString();
                          objStudent.SchoolName = dr["School_Name"].ToString();
                          objStudent.IsStudentActive = (dr["Is_Active"]).Equals(0) ? false : true;
                          objStudent.IsSpecialED = (dr["Special_Education"]).Equals(0) ? false : true;
                          objStudent.IsEnglishLearner = (dr["English_Learner"]).Equals(0) ? false : true;
                          DatasetUtility obj = new DatasetUtility();
                          SerializableDictionary<string, StudentScoresDO> ldStudentScoresStatus = new SerializableDictionary<string, StudentScoresDO>();
                          DataTable dtScoresStatus = obj.FilterTable(string.Concat("Student_Key ='", dr["Student_Key"].ToString(), "'"), dsStudentsDetails.Tables[1]);
                          foreach (DataRow drGradingPeriod in dtScoresStatus.Rows)
                          {
          
                              if (!ldStudentScoresStatus.ContainsKey(drGradingPeriod["Grading_Period_Name"].ToString()))
                              {
                                  StudentScoresDO objStudentScores = new StudentScoresDO();
                                  objStudentScores.IsScoreExists = Convert.ToBoolean(drGradingPeriod["Is_Score_Exists"]);
                                  objStudentScores.IsScoringCompleted = Convert.ToBoolean(drGradingPeriod["Is_Scoring_Completed"]);
                                  objStudentScores.IsScoresEnteredByAnotherTeacher = (Convert.ToBoolean(drGradingPeriod["Entered_By_AnotherTeacher"])).Equals(1) ? true : false;
                                  objStudentScores.TeacherKey = (objStudentScores.IsScoresEnteredByAnotherTeacher == true) ? Convert.ToInt32(drGradingPeriod["Teacher_Key"]) : 0;
                                  objStudentScores.TeacherName = (objStudentScores.IsScoresEnteredByAnotherTeacher == true) ? drGradingPeriod["Teacher_Name"].ToString() : string.Empty;
                                  ldStudentScoresStatus.Add(drGradingPeriod["Grading_Period_Name"].ToString(), objStudentScores);
                              }
                          }
                          object[][] objStudentScoresStatus = new object[ldStudentScoresStatus.Count][];
                          int iIndex = 0;
                          foreach (string strKey in ldStudentScoresStatus.Keys)
                          {
                              objStudentScoresStatus[iIndex] = new object[] { strKey, ((StudentScoresDO)ldStudentScoresStatus[strKey]) };
                              iIndex++;
                          }
                          objStudent.StudentScores = objStudentScoresStatus;
                          lstStudent.Add(objStudent);
                      }
                      return lstStudent;
                  }
          While getting the value of the StudentScores property from StudentDO this exception is raised:

          Code:
          public Object[][] StudentScores
                  {
                      get { return this._objStudentScores; }--Here
                      set { this._objStudentScores = value; }
                  }
          The version of .net is 3.5
          Last edited by Niheel; Jul 24 '10, 06:55 AM. Reason: please enclose all code in code tags [code] . . . [/code]

          Comment

          • adamstemper
            New Member
            • Jul 2010
            • 1

            #6
            solution?

            were you able to find a solution for this problem? I have a sub-sub class, and have the same problem. Only difference is I am using vb.net

            Comment

            Working...