You must Sign In to post a response.

Error in Web Services

Hey Friends, I have made one WebServices (For My Chat Application) to send and Receive Messages.Its working fine with receive message method,But gives an exception when any one send message



This is the exception

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Cannot serialize the DataTable. DataTable name is not set.
at System.Data.DataTable.WriteXmlSchema(XmlWriter writer, Boolean writeHierarchy)
at System.Data.DataTable.System.Xml.Serialization.IXmlSerializable.WriteXml(XmlWriter writer)
at System.Xml.Serialization.XmlSerializationWriter.WriteSerializable(IXmlSerializable serializable, String name, String ns, Boolean isNullable, Boolean wrapped)
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_AddMessageResponse(Object[] p)
at Microsoft.Xml.Serialization.GeneratedAssembly.ArrayOfObjectSerializer5.Serialize(Object objectToSerialize, XmlSerializationWriter writer)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle, String id)
at System.Xml.Serialization.XmlSerializer.Serialize(XmlWriter xmlWriter, Object o, XmlSerializerNamespaces namespaces, String encodingStyle)
at System.Web.Services.Protocols.SoapServerProtocol.WriteReturns(Object[] returnValues, Stream outputStream)
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns(Object[] returnValues)
at System.Web.Services.Protocols.WebServiceHandler.Invoke()
--- End of inner exception stack trace ---






And here is my send message code...

[WebMethod]
public DataTable AddMessage(string sDealer, string sUser, string sMsg, DataTable oDt)
{
if (oDt == null)
{
oDt = new DataTable();
oDt.Columns.Add(new DataColumn("UserName", typeof(string)));
oDt.Columns.Add(new DataColumn("Message", typeof(string)));
oDt.Columns.Add(new DataColumn("Date", typeof(string)));
}
DataRow oDr = oDt.NewRow();
oDr["UserName"] = sUser;
oDr["Message"] = sMsg;
oDr["Date"] = DateTime.Now.ToString();
oDt.Rows.Add(oDr);

string sTime = DateTime.Now.ToString();
string sAddText = sDealer + "~" + sUser + "~" + sMsg + "~" + sTime;
return oDt;
}




Whats the error??

Thanks And Regards
MoKsHShaH


Comments

Author: Danasegarane.A07 Sep 2010 Member Level: Gold   Points : 2

You are checking the datatable is null, if null, add column. Check the column existance,if the datatable is not null for the function


Sign In to post your comments