Click here to Skip to main content
15,944,835 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hi, I need to make a Web service that retrieves information from a Sql server 2008 table, and then fill a data GridView with the data. I need to build a response for consume the Xml data from the web service but I don't know how.

All I really need to know is how to return the DataBase query in XML format from the WS and then retrieve it in the client webSite>!!
Posted
Updated 5-Sep-13 18:52pm
v2
Comments
Thomas ktg 5-Sep-13 1:11am    
Have you not tried searching through google for your question?
Member 10253391 5-Sep-13 3:29am    
Hi, Yeah trust me, but its confusing because I don't have enough experience working with WS !
Nissim Salomon 5-Sep-13 1:58am    
Hi can you be more specific ? what part of the task you don't know how to do ?
Member 10253391 5-Sep-13 3:22am    
Its a kind of technical test for apply to a job. I don't know how to build the webMethod, I mean what kind of return should it have?, because they want me to retrieve the BD query result from the data base then call the WM in the client Site and then fill a data GridView with the WS response, it shouldn't be with a dataset, but I dont know another way to do this without it.
KmgKrishnan 5-Sep-13 2:13am    
Hi, If I understand your question correctly, are you trying to use an existing .Net web service in your application?
If yes, then you can simply add a service reference. You can see that folder in a windows application.

If you are planning to create a web service, you can use the WCF projects and implement the changes and publish. You would be able to use it in the similar way as I suggested above to consume.

Hi, I couldn't reply to your comment as i am seeing only xml attribute value (not the attribute names). That's why i am adding my response to the solution.

I am sorry as i couldn't find time to look into these details for long time.
I believe you would have already figured out the solution. Still i wanted to comment about my view on your results. If you can bring the xml data in the below format, it can simply be bound to grid using DataSet.ReadXml() method. I believe your results might be same as below. Please let me know if you find any issues.

XML
<Table>
<Row>
<DeptId>10</DeptId>
<DeptName>ACCOUNTING</DeptName>
<City>NEW YORK</City>
</Row>
<Row>
<DeptId>20</DeptId>
<DeptName>RESEARCH</DeptName>
<City>DALLAS</City>
</Row>
<Row>
<DeptId>30</DeptId>
<DeptName>SALES</DeptName>
<City>CHICAGO</City>
</Row>
<Row>
<DeptId>40</DeptId>
<DeptName>OPERATIONS</DeptName>
<City>BOSTON</City>
</Row>
</Table>


Once you brought up the results like above, then you can use the below code to view results as below.

VB
Dim dsGrid As DataSet = New DataSet()
Dim filePath As String = @"C:\Test_File.xml"
dsGrid.ReadXml(filePath)


DeptId DeptName City
======================================================
10 ACCOUNTING NEWYORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
 
Share this answer
 
There are so many reasons to either use WCF or ASP.Net WS. Based on Web Server, communication pattern and style, it can be chosen. I will leave it up to you.

If you would like to use WCF,
==============================
1. Add Service Reference in your .Net solution. This will help you to get the data in xml format.
2. If you have XML, then you can transform that to XSLT and it can be bound to asp.net grid view.

Below link can help you on how to convert to XSLT

http://decoding.wordpress.com/2008/12/22/aspnet-how-to-use-an-xmldatasource-with-a-gridview/[^]

3. Another way is to convert XML to a specific class and you can bind that to Grid View as given in the below link.

http://stackoverflow.com/questions/10057656/linq-to-xml-bind-to-gridview[^]

If you use generic ASP.Net WS,
================================
1. You would use HTTP Request/Response
2. Remaining steps are same as explained above in WCF.





Yours:
=======
hi, Yes I have all the client-server enviroment working good (tested), my doubt is how to retrieve the DATA BASE query result from the WS without a dataSet RETURN and then fill a datagridView, I made it in other projects with php+Mysql+Json , but Dunno how it works in a .net WS enviroment.
 
Share this answer
 
Comments
Member 10253391 8-Sep-13 23:37pm    
How can I load the XML file with data from the BD ?
KmgKrishnan 10-Sep-13 20:53pm    
There are multiple ways.
1. Pull the data as xml from the database itself.
Example: http://stackoverflow.com/questions/1564541/how-to-convert-records-in-a-table-to-xml-format-using-t-sql

2. After getting the dataset/datatable, we can populate xml file using .WriteXml method of dataset/datatable.
If you want this xml file with custom elements, you need to define the structure using xsd, then create .vb/C# file from that. Add them in your project and it can be used to load the data and then use .Writexml method.

Let me know if this answers your question and if you have any additional question.
Member 10253391 18-Sep-13 3:27am    
Krishnan currently Im Succesfully retrieving a XML Document with "writeXML", check the outPut:


<Table>
<deptno>10
<dname>ACCOUNTING
<loc>NEW YORK
</Table>
<Table>
<deptno>20
<dname>RESEARCH
<loc>DALLAS
</Table>
<Table>
<deptno>30
<dname>SALES
<loc>CHICAGO
</Table>
<Table>
<deptno>40
<dname>OPERATIONS
<loc>BOSTON
</Table>

I made the web Reference in the client Site, now I need to figure out how to Fill my gridView with this XML document returned from the WS !!!!!!

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