关于返回数据集的疑惑

qiaocm 2003-10-17 08:05:49
我在WebService开发中碰到这样一个问题 当如下
<WebMethod> function xx(Byval y As integer) as integer
当调用这个函数时可以正常返回结果,可当我得返回结果为数据集时,我在客户端调用则会报错,请各位帮忙,会是什么原因
...全文
35 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiaocm 2003-10-22
  • 打赏
  • 举报
回复
在Web端成功了(在IE中调用),在客户端调用又出现了问题
=======================================
未处理的“System.Net.WebException”类型的异常出现在 system.web.services.dll 中。

其他信息: 请求因 HTTP 状态 401 失败:Access Denied。
=======================================
错误位置在web引用中生成的单元

Public Function GetAuthors() As Authors
Dim results() As Object = Me.Invoke("GetAuthors", New Object(-1) {})
Return CType(results(0),Authors)
End Function
qiaocm 2003-10-22
  • 打赏
  • 举报
回复
答案知道了,问题有点低级,对不起!
qiaocm 2003-10-22
  • 打赏
  • 举报
回复
部分原代码
WEBService方面
Web方法1
<WebMethod()> _
Public Function GetDataSet() As DataSet
Dim connstr As String = "workstation id=QIAOCM;packet size=4096;user id=sa;data source=sanying;persist security info=True;initial catalog=test;password=sa"
Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(connstr)
Dim Adap As System.Data.SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter("select * from test", conn)
Dim x As DataSet
Adap.Fill(x)
Return x
End Function

Web方法2
<WebMethod()> _
Public Function SayHello(ByVal word As String) As String
Return word
End Function


客户端
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x As New localhost.Service1
x.Credentials = System.Net.CredentialCache.DefaultCredentials
'MyDataSet1.Merge(x.GetDataSet()) ' --失败
DataGrid1.DataSource = MyDataSet1.Tables(0)
Text = x.SayHello("ni") '成功
End Sub

当我指向数据集的时的报错为
========================================
未处理的“System.Web.Services.Protocols.SoapException”类型的异常出现在 system.web.services.dll 中。

其他信息: System.Web.Services.Protocols.SoapException: 服务器无法处理请求。 ---> System.ArgumentNullException: 值不能为空。
参数名: dataSet
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
at System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
at WebService1.Service1.GetDataSet() in c:\inetpub\wwwroot\WebService1\Service1.asmx.vb:line 97
--- 内部异常堆栈跟踪的结尾 ---
========================================

出错位置在Web引用中生成的单元的方法
Public Function GetDataSet() As MyDataSet
Dim results() As Object = Me.Invoke("GetDataSet", New Object(-1) {})’在这里报错
Return CType(results(0),MyDataSet)
End Function



请各位看看是什么原因,拜托!
rgbcn 2003-10-18
  • 打赏
  • 举报
回复
System.Data.DataRelation cannot be serialized because it does not have a
default public constructor.


CAUSE
This is by design. The DataTable, DataRow, DataView, and DataViewManager
objects are not serializable and cannot be returned from a Web Service. In
order to return less than a complete DataSet, you have to copy the data you
wish to return to a new DataSet.

RESOLUTION
You can resolve this issue by returning a DataSet instead of a DataTable.
DataSets can contain one or more DataTables.

91bct 2003-10-18
  • 打赏
  • 举报
回复
没有代码,也没有说明报什么错...
呵呵
fgyAdmin 2003-10-18
  • 打赏
  • 举报
回复
报什么错误呢?
JB-Zhang 2003-10-18
  • 打赏
  • 举报
回复
我试过,返回dataset是没问题的,返回datatable就不行
minajo21 2003-10-17
  • 打赏
  • 举报
回复
返回的是dataset?
qiaocm 2003-10-17
  • 打赏
  • 举报
回复
就是,可是我却无法调用,是为什么呢?请各位同行帮忙?

12,162

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 Web Services
社区管理员
  • Web Services社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧