473,473 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

7 New Member
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:

Expand|Select|Wrap|Line Numbers
  1. public class StudentDO
  2.     {
  3.         private int _iStudentKey;        
  4.         private string _strStudentName;
  5.         private string _strSchoolName;
  6.         private string _strDistrictName;
  7.         private bool _bIsStudentActive;
  8.         private bool _bIsSpecialED;
  9.         .
  10.         .
  11.         .
  12.         private Object[][] _objStudentScores; 
  13.  
  14.                 public StudentDO()
  15.         {
  16.             this._iStudentKey = 0;
  17.             this._strStudentName = string.Empty;
  18.             this._strSchoolName = string.Empty;
  19.             this._strDistrictName = string.Empty;
  20.             this._bIsStudentActive = false;
  21.             this._bIsSpecialED = false;
  22.             this._bIsEnglishLearner = false;
  23.             this._objStudentScores = new Object[10][];
  24.         }
  25.  
  26.         public int StudentKey
  27.         {
  28.             get { return this._iStudentKey; }
  29.             set { this._iStudentKey = value; }
  30.         }
  31.         .
  32.         .
  33.         .
  34.  
  35.         public Object[][] StudentScores
  36.         {
  37.             get { return this._objStudentScores; }
  38.             set { this._objStudentScores = value; }
  39.         }
  40.     }
  41. }
The inner class is :
Expand|Select|Wrap|Line Numbers
  1.     public class StudentScoresDO
  2.     {
  3.       private bool _bIsScoreExists;
  4.       private bool _bIsScoringCompleted;        
  5.       private bool _bIsScoresEnteredByAnotherTeacher;
  6.       private int _iTeacherKey;
  7.       private string _strTeacherName;
  8.       private string _strComments;
  9.       private Object[][] _objItemScores;
  10.     }
Jul 23 '10 #1
5 2068
newb16
687 Contributor
Is it java?
Jul 23 '10 #2
khushboosoni
7 New Member
@newb16
No it is in C#
Jul 23 '10 #3
Joseph Martell
198 Recognized Expert New Member
Can you show us the code where the exception is actually thrown?

Also, what version of the .Net framework are you using?
Jul 23 '10 #4
khushboosoni
7 New Member
The complete details of the exception is:

System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: The type Com.SchoolCity.ReportCards.ReportCardLibrary.Data. StudentScoresDO was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically.
at System.Xml.Serialization.XmlSerializationWriter.Wr iteTypedPrimitive(String name, String ns, Object o, Boolean xsiType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriter1.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriter1.Write4_StudentDO(String n, String ns, StudentDO o, Boolean isNullable, Boolean needType)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlS erializationWriter1.Write7_ArrayOfStudentDO(Object o)
at Microsoft.Xml.Serialization.GeneratedAssembly.List OfStudentDOSerializer.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(X mlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter, Object o, XmlSerializerNamespaces namespaces)
at System.Xml.Serialization.XmlSerializer.Serialize(T extWriter textWriter, Object o)
at System.Web.Services.Protocols.XmlReturnWriter.Writ e(HttpResponse response, Stream outputStream, Object returnValue)
at System.Web.Services.Protocols.HttpServerProtocol.W riteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.Wr iteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.In voke()


And the code behind is as follows:

Expand|Select|Wrap|Line Numbers
  1. public List<StudentDO> GetStudentsForReportCard(int iTeacherKey, int iLocationKey, string strGrade, string strSchoolYear, int iClassKey)
  2.         {
  3.             List<StudentDO> lstStudent = new List<StudentDO>();
  4.  
  5.             DataSet dsStudentsDetails = GetStudents(iTeacherKey, iLocationKey, strGrade, strSchoolYear, iClassKey);
  6.             if (!CommonUtility.IsValidObject(dsStudentsDetails)) return null;
  7.             foreach (DataRow dr in dsStudentsDetails.Tables[0].Rows)
  8.             {
  9.                 StudentDO objStudent = new StudentDO();
  10.                 objStudent.StudentKey = Convert.ToInt32(dr["Student_Key"]);
  11.                 objStudent.StudentName = dr["Student_Name"].ToString();
  12.                 objStudent.DistrictName = dr["District_Name"].ToString();
  13.                 objStudent.SchoolName = dr["School_Name"].ToString();
  14.                 objStudent.IsStudentActive = (dr["Is_Active"]).Equals(0) ? false : true;
  15.                 objStudent.IsSpecialED = (dr["Special_Education"]).Equals(0) ? false : true;
  16.                 objStudent.IsEnglishLearner = (dr["English_Learner"]).Equals(0) ? false : true;
  17.                 DatasetUtility obj = new DatasetUtility();
  18.                 SerializableDictionary<string, StudentScoresDO> ldStudentScoresStatus = new SerializableDictionary<string, StudentScoresDO>();
  19.                 DataTable dtScoresStatus = obj.FilterTable(string.Concat("Student_Key ='", dr["Student_Key"].ToString(), "'"), dsStudentsDetails.Tables[1]);
  20.                 foreach (DataRow drGradingPeriod in dtScoresStatus.Rows)
  21.                 {
  22.  
  23.                     if (!ldStudentScoresStatus.ContainsKey(drGradingPeriod["Grading_Period_Name"].ToString()))
  24.                     {
  25.                         StudentScoresDO objStudentScores = new StudentScoresDO();
  26.                         objStudentScores.IsScoreExists = Convert.ToBoolean(drGradingPeriod["Is_Score_Exists"]);
  27.                         objStudentScores.IsScoringCompleted = Convert.ToBoolean(drGradingPeriod["Is_Scoring_Completed"]);
  28.                         objStudentScores.IsScoresEnteredByAnotherTeacher = (Convert.ToBoolean(drGradingPeriod["Entered_By_AnotherTeacher"])).Equals(1) ? true : false;
  29.                         objStudentScores.TeacherKey = (objStudentScores.IsScoresEnteredByAnotherTeacher == true) ? Convert.ToInt32(drGradingPeriod["Teacher_Key"]) : 0;
  30.                         objStudentScores.TeacherName = (objStudentScores.IsScoresEnteredByAnotherTeacher == true) ? drGradingPeriod["Teacher_Name"].ToString() : string.Empty;
  31.                         ldStudentScoresStatus.Add(drGradingPeriod["Grading_Period_Name"].ToString(), objStudentScores);
  32.                     }
  33.                 }
  34.                 object[][] objStudentScoresStatus = new object[ldStudentScoresStatus.Count][];
  35.                 int iIndex = 0;
  36.                 foreach (string strKey in ldStudentScoresStatus.Keys)
  37.                 {
  38.                     objStudentScoresStatus[iIndex] = new object[] { strKey, ((StudentScoresDO)ldStudentScoresStatus[strKey]) };
  39.                     iIndex++;
  40.                 }
  41.                 objStudent.StudentScores = objStudentScoresStatus;
  42.                 lstStudent.Add(objStudent);
  43.             }
  44.             return lstStudent;
  45.         }
  46.  
While getting the value of the StudentScores property from StudentDO this exception is raised:

Expand|Select|Wrap|Line Numbers
  1. public Object[][] StudentScores
  2.         {
  3.             get { return this._objStudentScores; }--Here
  4.             set { this._objStudentScores = value; }
  5.         }
The version of .net is 3.5
Jul 24 '10 #5
adamstemper
1 New Member
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
Jul 29 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Stephane Ninin | last post by:
Hello all, I am trying to play with nested class in a script I am making, and I am not sure I really understand how they work. Here is some code: __all__ =
9
by: OKB (not okblacke) | last post by:
For a variety of reasons, I'm interested in putting together some code that will allow me to created structures out of nested classes, something like: class class1: def methA(self): print...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
9
by: Jay Douglas | last post by:
Hello, I am needing to pass a class object (this) by reference to a method in a different class. When I do the following code I get the error (Cannot pass '<this>' as a ref or out argument because...
9
by: Joel Moore | last post by:
I'm a little confused here. If I have the following: Public ClassA Friend varA As Integer Private varB As Integer Private ClassB Public Sub MethodA() ' How can I access varA and varB here?...
4
by: Mr Dyl | last post by:
I'm trying to declare the following friendship and VS.Net 2003 is complaining: template <class T> class Outter { class Inner {...} ... }
4
by: rach | last post by:
I just started to learn C++. I copied the following code from a data structure textbook to a ".h" file and couldn't compile it. The code contains three template interfaces. One inherits another. The...
2
by: tron.thomas | last post by:
The following code will print a message only once: class PrintOnce: printOnce = True def __init__(self): if PrintOnce.printOnce: print 'Printing once.' PrintOnce.printOnce = False first =...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
2
by: John Doe | last post by:
Hi, I am trying to port some C class routines into C++. THe original functions are use to set/get properties of buttons inside a toolbar : // This function is used to set btton text //...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.