Serialization calss is assign to Property type object in class
-
Friday, May 04, 2012 6:30 AM
Hi Chaps,
I am facing an issue, Please gothrough the code once.
I create a method GetemployeeDetails in WebService. This method retruns Employee data.
Here i have to pass either personal details or corporate details based on the selected contactDetails.
Suppose, if i selected ContactDetailsType is personal. I have to pass personal details and these details object is assign to Item property in Employee class. The Item property datatype is object.
so when I call this service call in my application it gives runtime error.
This code is in Webservice
public class Employee { private object item; public object Item { get { return item; } set { item = value; } } private string welcomeNote; public string WelComeNote { get { return welcomeNote; } set { welcomeNote = value; } } private ContactDetails contactDetailsType; public ContactDetails ContactDetailsType { get { return contactDetailsType; } set { contactDetailsType = value; } } } public enum ContactDetails { personal, Corporate } public class PersonalDetails { private string name; public string Name { get { return name; } set { name = value; } } private string dob; public string DOB { get { return dob; } set { dob = value; } } } public class CorporateDetails { private string name; public string Name { get { return name; } set { name = value; } } private string dob; public string DOB { get { return dob; } set { dob = value; } } } public class Service { public Employee GetEmployeeDetails(int EmployeeId) { Employee employee = new Employee(); if (employeeid = 123) { employee.ContactDetailsType = ContactDetails.personal; employee.WelComeNote = "Welcome Mr"; PersonalDetails persondetails = new PersonalDetails(); persondetails.DOB = DateTime.Now.ToShortDateString(); persondetails.Name = "Peete"; employee.Item = persondetails; } return employee; } }The below code in Application, webservice call
public Employee GetEmployeeDetails()
{
Service1SoapClient client = new Service1SoapClient();
Employee ob = client.GetEmployeDetails(14);
}error code block
Type was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. at System.Xml.Serialization.XmlSerializationWriter.WriteTypedPrimitive(String name, String ns, Object o, Boolean xsiType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write1_Object(String n, String ns, Object o, Boolean isNullable, Boolean needType) at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriterObject.Write2_anyType(Object o)
Regards,
Looser....... :-)
Regards, Looser.
- Edited by am Looser Friday, May 04, 2012 6:36 AM
All Replies
-
Tuesday, May 08, 2012 4:31 AM
I am not sure if your code is working any how, are you trying to make WCf service?
you really missing ServiceContract DataContract etc..
For Item type object My suggestion would to define some Interface that would be base for all your dependent class and use that Interface here.
For WCF here is great links.
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/07331239-3ea2-4a79-88af-4e71ef197617
Best Regards Sanjay Pant [Metadesign Solutions]
-
Tuesday, June 12, 2012 9:06 AM
I got solution for this. thnks for your replying
on top of this class i have to place the below lines...
[XmlInclude(typeof(PersonalBusinessAssociateType))]
[XmlInclude(typeof(CorporateBusinessAssociateType))]public class Service
{
public Employee GetEmployeeDetails(int EmployeeId)
{
Employee employee = new Employee();
if (employeeid = 123)
{
employee.ContactDetailsType =
ContactDetails.personal;
employee.WelComeNote =
"Welcome Mr";
PersonalDetails persondetails = new PersonalDetails();
persondetails.DOB =
DateTime.Now.ToShortDateString();
persondetails.Name =
"Peete";
employee.Item = persondetails;
}
return employee;
}
}Regards, Looser.
- Marked As Answer by am Looser Tuesday, June 12, 2012 9:06 AM

