我试图无济于事地将自定义对象传递给asmx Web服务。我有一个DLL,其中包含我的主项目以及Web服务项目中引用的类。
这行代码( CompleteDataTransport 是一个DataSyncTransport对象):
result = TestService.WholeDataUpload(10, CompleteDataTransport, AttachmentHelper.Authenticate("12345678"))
引发错误:无法将类型DataSyncTransport的值转换为DataOnDataTables。
我在错误中搜索了Google,并提出了this这样的问题,该问题基本上说该对象必须可序列化才能将其传递给服务。
我做到了。这是我的课:
Imports System.Data
Imports System.Xml.Serialization
<Serializable()>
<XmlRoot("DataSyncTransport")>
Public Class DataSyncTransport
<XmlElement("WholeData")>
Property WholeData As New List(Of DataOnDataTables)
End Class
<Serializable()>
Public Class DataOnDataTables
<XmlElement("IdKey")>
Property IdKey As String
<XmlElement("ColumnsValidation")>
Property ColumnsValidation As String
<XmlElement("TableName")>
Property TableName As String
<XmlElement("DataTableForUpload")>
Property DataTableForUpload As New DataTable
End Class
这是Web服务方法:
Public Function WholeDataUpload(ByVal appId As Integer, ByVal
DataSyncTransport As DataSyncTransport, ByVal token As String) As String
Dim _result As String = String.Empty
For Each item As DataOnDataTables In DataSyncTransport.WholeData()
Try
_result = Upload(appId, item.TableName, item.ColumnsValidation,
item.DataTableForUpload, token)
Catch ex As Exception
_result = ex.Message
End Try
Next
Return _result
End Function
我做错了什么?请帮忙。
谢谢!