需要帮助.net Web Services使用WCF。 [英] Need help with .net Web Services using WCF.

查看:73
本文介绍了需要帮助.net Web Services使用WCF。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建一个Web服务,从Sql server 2008表中检索信息,然后用数据填充数据GridView。我需要构建一个响应来消费来自Web服务的Xml数据,但我不知道如何。



我真正需要知道的是如何返回来自WS的XML格式的DataBase查询,然后在客户端webSite中检索它> !!

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>!!

推荐答案

使用WCF或ASP.Net WS的原因有很多。基于Web Server,通信模式和风格,可以选择。我会留给你。



如果你想使用WCF,

========== ====================

1.在.Net解决方案中添加服务参考。这将帮助您以xml格式获取数据。

2.如果您有XML,那么您可以将其转换为XSLT,它可以绑定到asp.net网格视图。



以下链接可以帮助您如何转换为XSLT



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



3.另一种方式是转换XML到特定的类,您可以将其绑定到Grid View,如下面的链接所示。



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



如果您使用通用ASP.Net WS,

================================

1.您将使用HTTP请求/回复

2.剩余步骤与WCF上述相同。











你的:

=======

是的我有所有客户端 - 服务器环境工作良好(经过测试),我的疑问是如何从WS中检索DATA BASE查询结果而没有dataSet RETURN然后填充datagridView,我用其他项目用php + Mysql + Json做了,但是Dunno如何在.net WS环境中工作。
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:
=======
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.


我无法回复你的评论,因为我只看到xml属性值(不是属性名称)。这就是为什么我要在解决方案中添加我的回复。



我很抱歉因为我找不到时间长时间查看这些细节。

我相信你已经找到了解决方案。我仍然想评论我对你的结果的看法。如果您可以使用以下格式提供xml数据,则可以使用DataSet.ReadXml()方法将其绑定到网格。我相信您的结果可能与以下相同。如果您发现任何问题,请告诉我。



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.

<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.

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





DeptId DeptName City

=================================== =====================

10会计纽约

20研究达拉斯

30销售芝加哥

40运营波士顿



DeptId DeptName City
======================================================
10 ACCOUNTING NEWYORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON


这篇关于需要帮助.net Web Services使用WCF。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆