Public Function GetAuthors() As Authors
Dim results() As Object = Me.Invoke("GetAuthors", New Object(-1) {})
Return CType(results(0),Authors)
End Function
部分原代码
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.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
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.