我可以将数据表作为Web服务的参数传递 [英] Can I pass a datatable as parameter of a web service

查看:89
本文介绍了我可以将数据表作为Web服务的参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到错误序列化消息体时出错:'生成XML文档时出错。'当我尝试将DataTable传递给Web服务时。





你能帮我吗。

解决方案

DataTables是XML可序列化的,所以你可以使用它们作为来自XML Web服务的输入和输出。

参考:从XML Web服务中使用DataSet [ ^ ]



这可能会有所帮助。


< pre lang =cs> [WebMethod]
public DataTable ExcelExport(dt)
{
DataTable dt = new DataTable()
// 您的代码
return dt;

}


将dataTable添加到数据集,&使用xmlDataDocument对象将数据集传递给webservice: -



 //将表添加到此数据集
DataSet obj = new DataSet() ;
//创建xmlDataDocument对象
//将此xdd对象传递给webservice
XmlDataDocument xdd = new XmlDataDocument(obj);
//从XmlDataDocument获取数据集
obj = xdd.DataSet;


I got an error "There was an error in serializing body of message : 'There was an error generating the XML document.' When I am trying to pass a DataTable to a webservice.


Could you please help me.

解决方案

DataTables are XML serializable, and so you can use them as both input and output from an XML Web Service.
Refer:Consuming a DataSet from an XML Web Service[^]

This may help.


[WebMethod]
public DataTable ExcelExport(dt)
  {
     DataTable  dt = new DataTable()
     // your Code
     return dt;

  }


add dataTable to dataset, & use xmlDataDocument object to pass dataset to webservice:-

//add table to this dataset
DataSet obj = new DataSet();
//create xmlDataDocument object
//pass this xdd object to webservice
XmlDataDocument xdd = new XmlDataDocument(obj);
//get dataset from XmlDataDocument
obj = xdd.DataSet;


这篇关于我可以将数据表作为Web服务的参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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