将数据从我的应用程序传递到ASMX webservice
时,总是会出现转换错误我的WebService代码
Public Function SetAlterLogTrx(ByVal qsTrx As List(Of String)) As String
Dim oStatus As New LogAlterStatusDsp
Dim iRec As Integer = 0
Using DBCONN As New SqlConnection()
Dim strConnString As String = ConfigurationManager.ConnectionStrings("Conn").ConnectionString
DBCONN.ConnectionString = sDBConnString
If qsTrx.Count = 0 Then
Return "Failed"
Else
Dim sQueryList As Array = qsTrx.ToArray
For Each sQuery As String In sQueryList
Using UpdateOutCommand As New SqlCommand(sQuery, DBCONN)
Try
With DBCONN
.Open()
iRec = UpdateOutCommand.ExecuteNonQuery()
.Close()
End With
Catch ex As Exception
Return "Failed"
End Try
End Using
Next
Return "Ok"
End If
End Using
End Function
我的客户代码
dim qsArray() as string
'This array has many lines
Using oSvc As New AnfaEngine.AnfaWSSoapClient
Dim svcReplay As AnfaEngine.LogAlterStatusDsp
Dim oList As New List(Of String)
oList.AddRange(qsArray.Cast(Of String).ToList)
svcReplay = oSvc.SetAlterLogTrx(oList)
End Using
我总是收到此错误消息:
无法将'System.Collections.Generic.List`1 [System.String]'类型的对象强制转换为'WS.ArrayOfString'。
我该怎么做才能解决这个问题。
答案 0 :(得分:0)
使用“添加服务引用”引用服务时,请尝试使用“高级”选项卡指定使用List(Of T)
作为集合类型。
如果这不起作用,那么您只需向服务发送它想要接收的内容。
答案 1 :(得分:-1)
我在客户端代码中解决了我的问题,如下所示:
dim qsArray() as string
'This array has many lines
Using oSvc As New AnfaEngine.AnfaWSSoapClient
Dim svcReplay As AnfaEngine.LogAlterStatusDsp
Dim oList As New List(Of AnfaEngine.ArrayOfString)
oList.AddRange(qsArray.Cast(Of String).ToList)
svcReplay = oSvc.SetAlterLogTrx(oList)
End Using