Hi,
I am doing silverlight project by using WCF. am unable to deSerilize the xml string into list of objects. I had search for solution but i did't find sol.
The error is :
Error in line 1 position 13. Expecting element 'ArrayOfContactService.newDataSet' from namespace 'http://schemas.datacontract.org/2004/07/AddingContacts.Web'.. Encountered 'Element' with name 'NewDataSet', namespace ''.Here NewDataSet is while creating dataset it was created automatically
can u help me ASAP.
Please find the bellow code
my xml string is :
<NewDataSet> <Table> <Name>vema
</Name> <Age>24
</Age>
<Email>[email protected]</Email> <Mobile>589787759
</Mobile> <Address>gfjsag
</Address> <CreatedDate>2012-07-24T17:36:29.25+05:30
</CreatedDate> </Table> <Table> <Name>Rama Krishna
</Name> <Age>25
</Age> <Email>[email protected]</Email>
<Mobile>6558689j
</Mobile>
<Address>hjhjhjh
</Address> <CreatedDate>2012-07-24T18:46:08.877+05:30
</CreatedDate>
</Table> </NewDataSet> This is my Service Class
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Web.Configuration;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
using System.Text;
namespace AddingContacts.Web
{
[ServiceContract(Namespace = "")]
[SilverlightFaultBehavior]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class ContactService
{
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}
/// <summary>
/// This class is used as datatype for generic list for send the data over the network
///
[DataContract]
public class newDataSet
{
public List<table> NewDataSet=new List<table>();
}
[DataContract]
public class table
{
[DataMember]
public List<contacts> Table = new List<contacts>();
}
[DataContract]
public class contacts
{
[DataMember]
public string Name { get; set; }
[DataMember]
public string Age { get; set; }
[DataMember]
public string Email { get; set; }
[DataMember]
public string Mobile { get; set; }
[DataMember]
public string Address { get; set; }
[DataMember]
public DateTime CreatedDate { get; set; }
}
/// <summary>
/// This Method is used to show all contacts in the gridview of silverlight popups
/// </summary>
/// Created By: Vema Reddy
/// <returns></returns>
[OperationContract]
public List<newDataSet> fetchContacts()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = WebConfigurationManager.ConnectionStrings["addContactConnectoionString"].ConnectionString;
SqlCommand cmd = new SqlCommand("USP_GetContacts", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
DataTable dt = new DataTable();
con.Close();
da.Fill(ds);
string resultxml = ds.GetXml();
List<newDataSet> listobj = new List<newDataSet>();
try
{
using (StringReader reader = new StringReader(resultxml))
{
using (XmlReader xmlReader = XmlReader.Create(reader))
{
var serializer = new DataContractSerializer(typeof(List<newDataSet>));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(resultxml));
listobj = (List<newDataSet>)serializer.ReadObject(stream);
}
}
catch (Exception ex)
{
}
finally
{
}
return listobj;
}
}