[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Convert Rest response to DataSet at client c#

Posted on 2013-12-01
1
Medium Priority
?
2,751 Views
Last Modified: 2013-12-01
I'm returning a DataSet with my Rest Call. How can I read it back into a DataSet or JSON or XML at the client?

My server code is:
        public DataSet GetDataSet(string strSQL)
        {
            DataSet ds = new DataSet();
           //populate ds here
            return ds;
        }
my contract is:

        [OperationContract]
        [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml,
            BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "MyHttpGetDataSet/{value}")]
        DataSet GetDataSet(string value);

my client code is:
            HttpClient client = new HttpClient();
            String url = System.Web.HttpUtility.HtmlEncode("http://localhost:3729/HttpService.svc/MyHttpGetDataSet/SELECT id FROM Table1");

            HttpResponseMessage wcfResponse = client.GetAsync(url).Result;
            HttpContent stream = wcfResponse.Content;
            var data = stream.ReadAsStringAsync();

Reading data.Return.ToString() shows:
<GetDataSetResponse xmlns=\"http://tempuri.org/\"><GetDataSetResult><xs:schema id=\"NewDataSet\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns=\"\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"><xs:element name=\"NewDataSet\" msdata:IsDataSet=\"true\" msdata:UseCurrentLocale=\"true\"><xs:complexType><xs:choice minOccurs=\"0\" maxOccurs=\"unbounded\"><xs:element name=\"Table1\"><xs:complexType><xs:sequence><xs:element name=\"Branch\" type=\"xs:string\" minOccurs=\"0\"/></xs:sequence></xs:complexType></xs:element></xs:choice></xs:complexType></xs:element></xs:schema><diffgr:diffgram xmlns:diffgr=\"urn:schemas-microsoft-com:xml-diffgram-v1\" xmlns:msdata=\"urn:schemas-microsoft-com:xml-msdata\"><NewDataSet xmlns=\"\"><Table1 diffgr:id=\"Table11\" msdata:rowOrder=\"0\"><Branch>Wholesale Department</Branch></Table1><Table1 diffgr:id=\"Table12\" msdata:rowOrder=\"1\"><Branch>Brisbane Sales</Branch></Table1><Table1 diffgr:id=\"Table13\" msdata:rowOrder=\"2\"><Branch>Mackay Sales</Branch></Table1><Table1 diffgr:id=\"Table14\" msdata:rowOrder=\"3\"><Branch>Sydney Sales</Branch></Table1><Table1 diffgr:id=\"Table15\" msdata:rowOrder=\"4\"><Branch>Melbourne Sales</Branch></Table1><Table1 diffgr:id=\"Table16\" msdata:rowOrder=\"5\"><Branch>Adelaide Sales</Branch></Table1><Table1 diffgr:id=\"Table17\" msdata:rowOrder=\"6\"><Branch>AEA Head Office</Branch></Table1><Table1 diffgr:id=\"Table18\" msdata:rowOrder=\"7\"><Branch>Export Department</Branch></Table1><Table1 diffgr:id=\"Table19\" msdata:rowOrder=\"8\"><Branch>All Sales Branches</Branch></Table1><Table1 diffgr:id=\"Table110\" msdata:rowOrder=\"9\"><Branch>Brisbane Northside</Branch></Table1><Table1 diffgr:id=\"Table111\" msdata:rowOrder=\"10\"><Branch>Perth Sales</Branch></Table1><Table1 diffgr:id=\"Table112\" msdata:rowOrder=\"11\"><Branch>Rockhampton Sales</Branch></Table1></NewDataSet></diffgr:diffgram></GetDataSetResult></GetDataSetResponse>
0
Comment
Question by:Netlink2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 1

Accepted Solution

by:
Netlink2 earned 0 total points
ID: 39688118
It wasn't easy, but I found it:
            HttpClient client = new HttpClient();
            String url = System.Web.HttpUtility.HtmlEncode("http://localhost:3729/HttpService.svc/MyHttpGetDataSet/SELECT Branch FROM AEA_Branches");

            HttpResponseMessage wcfResponse = client.GetAsync(url).Result;
            HttpContent stream = wcfResponse.Content;
            var data = stream.ReadAsStringAsync();

            String dataString = data.Result.ToString();
            XmlDocument bodyDoc = new XmlDocument();
            bodyDoc.LoadXml(dataString);

            DataSet ds = new DataSet();

            ds.ReadXml(new XmlTextReader(new StringReader(bodyDoc.InnerXml)), XmlReadMode.ReadSchema);
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question