Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I got an error "There was an error in serializing body of message : 'There was an error generating the XML document.' When I am trying to pass a DataTable to a webservice.


Could you please help me.
Posted
Updated 26-Aug-18 23:38pm
v3
Comments
What is the InnerException?

"But It works in the same application." -> Not clear.

DataTables are XML serializable, and so you can use them as both input and output from an XML Web Service.
Refer:Consuming a DataSet from an XML Web Service[^]

This may help.
 
Share this answer
 
C#
[WebMethod]
public DataTable ExcelExport(dt)
  {
     DataTable  dt = new DataTable()
     // your Code
     return dt;

  }
 
Share this answer
 
add dataTable to dataset, & use xmlDataDocument object to pass dataset to webservice:-

//add table to this dataset
DataSet obj = new DataSet();
//create xmlDataDocument object
//pass this xdd object to webservice
XmlDataDocument xdd = new XmlDataDocument(obj);
//get dataset from XmlDataDocument
obj = xdd.DataSet;
 
Share this answer
 
You can pass a datatable to a webservice only if you give it a tablename.
 
Share this answer
 
Comments
Vincent Maverick Durano 24-Aug-18 12:17pm    
Please don't respond to old threads like this as it brings to the top list which pushes new threads at the bottom.
Another option: convert your table to JSON - now it's just a string.


 
Share this answer
 
Comments
Vincent Maverick Durano 24-Aug-18 12:18pm    
I agree. But this is an old-thread.
W Balboos, GHB 24-Aug-18 12:45pm    
Per your reply to Solution 4 - I just pulled it off the list - which I rarely if ever check for currency as it's the 'live' list. But Alas, the deed is done.

2014 !
Vincent Maverick Durano 24-Aug-18 17:11pm    
That's what I thought. Sometimes, it happens to me too. Replying to old-threads without noticing the posted date because someone just revived it.
Richard Deeming 28-Aug-18 8:40am    
I guess Sean hasn't contacted you yet?

He sent me an email three weeks ago saying: "we don't want to discourage people from answering old questions by indicating that the age of the question is a problem".

:)
Vincent Maverick Durano 28-Aug-18 9:03am    
@Richard - nope I didn't. Well, thanks for the heads up. I'll keep a note on that. :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900