Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a WCF service to publish a DataTable. The data can be viewed in http://localhost:1234/Service1.svc/TableName in XML format. In my application, I use the code below:
C#
string url = "http://localhost:48677/Service1.svc/GetDataTable";
var webClient = new System.Net.WebClient();
string data = webClient.DownloadString(url);

How can the string data be converted into a DataTable? Thanks.
Posted
Comments
[no name] 5-Sep-13 9:33am    
What? You are calling a service method that returns a DataTable and you are trying to get that datatable as a string and then convert it back to a datatable? Why?
shaning 5-Sep-13 9:50am    
To ThePhantomUpvoter:
Thanks for your post. I am new in WCF application. My project scenario is below:
1) Create a WCF project that posts a table data (from a Database).
2) In an application project, I can retrieve the data in 1) and then convert it into a DataTable again.
3) Modify the DataTable in 2) and then save it as new Table into the Oracle DB.
I have done 1) and 3), but nor 2). Per your experience, what approach should I use? Thanks for your advice.

 
Share this answer
 
Comments
shaning 5-Sep-13 9:52am    
To Jameel: Thanks for your post. I tried the approach as you recommended. But I got the exception: DataTable does not support schema inference from Xml.
DataTable myDataTable = new DataTable();
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(new Uri(url));
myRequest.Method = "GET";

System.Net.WebResponse myResponse;
try {
myResponse = myRequest.GetResponse();
using (System.IO.Stream responseStream = myResponse.GetResponseStream()) {
myDataTable.ReadXml(responseStream);
}
} catch (Exception ex) {
throw new Exception("Got an error " + ex.Message);
}
Please provide your advice if you can. Thanks.
 
Share this answer
 

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