WebService的类型化DataTable返回问题 [英] Typed DataTable Return problem from WebService

查看:111
本文介绍了WebService的类型化DataTable返回问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个WinForm应用程序,并且在此项目中也使用了Web服务.问题是;
解决方案中有3个项目. I>数据层,II>服务层,III>表示层.数据层中有一些类型化的数据集,我可以毫无问题地填充该数据集并将其返回到表示层.另一方面,当我尝试在此数据集中返回一个数据表时,该数据表返回空.我检查并获得;类型化的数据表将填充在数据层中,并返回到服务层.数据表仍填充在服务层上.但是,当将其返回到应用程序层时,它变得空了.这是我使用的示例代码.我认为DataTables可以作为数据集在Web服务上返回.我使用类型化数据表,但也应将其返回.我错了吗?

在数据层上:

Hi all,
I have a WinForm application and I also use a web service in this project. The problem is that;
There is 3 project in the solution. I>Data layer, II>Service Layer, III>Presentation Layer. There is some of typed DataSet in Data Layer and I can fill and return this dataset to the presentation layer without any problem. On the other hand, when I try to return a datatable in this dataset, the datatable returns empty. I checked and obtain that; the typed datatable is filled in Data Layer and returns to Service layer. The datatable is still fill on the service layer. But, when return it to the application layer, it is getting empty. Here is the sample code I used. I think DataTables can be returned on webservices as DataSets. I use Typed Datatable but it should be returned as well. Am I wrong?

On the Data Layer:

<br />
<pre lang="c#">public StudentDS.EXAMSDataTable ExamTable()<br />
        {<br />
            SelectAll(dataSet.EXAMS); //This method fills the EXAMS table in dataset.<br />
            return dataSet.EXAMS;<br />
        }</pre><br />




在服务层:




On the Service Layer:

[WebMethod(Description = "Returns EXAMS datatable")]
        public StudentDS.EXAMSDataTable WsExamTable()
        {
            StudentDS.EXAMSDataTable dt = myDataAccess.ExamTable(); //Returns filled Exam table from Data Access Layer
            return dt; //NOTE : The table is filled at this stage
        }



在表示层上:



On the Presentation Layer:

private void btFill_Click(object sender, EventArgs e)
{
    dataGridView1.DataSource = myService.WsExamTable(); //NOTE : The table comes EMPTY from Service Layer at this stage
}




那么,是否有错误或如何从Web服务返回填充的数据表?
BR




So, is there a mistake or how can I return filled datatable from a web service?
BR

推荐答案

看起来不可能这样:
http://support.microsoft.com/kb/306134 [
Looks like this isn''t possible:
http://support.microsoft.com/kb/306134[^]

You could convert it to xml something like this:
DataTable dt = myDataAccess.ExamTable();              
XmlDocument XMLDoc = new XmlDocument();
XMLDoc.LoadXml(table.DataSet.GetXml());



祝您好运!



Good luck!


您可以通过Web服务传递数据集,但不能通过数据表传递数据集.只需将其保留在数据集中即可. DataSet已经可以序列化,但是DataTable不是.快点吧.
You can pass a DataSet through the Web Service but not a DataTable. Just leave it in the DataSet. The DataSet is already serializeable, but a DataTable is not. Go figure.


这篇关于WebService的类型化DataTable返回问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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