如何在 VB.NET 中为 WSDL 参数化对象成员
How to parameterise a object member in VB.NET for WSDL
我有一些代码可以填充 VB.NET 中的 SOAP 请求。我从 SQL 查询中获取数据,并通过对象成员 运行 来填充每个数据。我正在尝试找到一种快速(ish)方法来在成员为空时不提供该成员,而不是在应用它之前检查每个值。由于 SQL 数据首先来自管道分隔文件,我们永远不会得到 NULL,只是在 SOAP 请求中作为“”发送的空单元格。
有没有办法使用变量而不是其字面名称来定义对象成员?
UpLB_request_Items.Spare8 = Convert.ToString(SourceDataSet.tables(0).Rows(i)(colSPARE8))
UpLB_request_Items.Spare9 = Convert.ToString(SourceDataSet.tables(0).Rows(i)(colSPARE9))
UpLB_request_Items.Spare10 = Convert.ToString(SourceDataSet.tables(0).Rows(i)(colSPARE10))
Call IterateObject(UpLB_request_Items)
所以这会用 SQL 数据 (SourceDataSet) 中的值填充每个成员,然后我可以将完成的对象发送到 Sub 以在我实际将其发送到 web 服务之前检查每个值
Sub IterateObject(objName)
Dim CollName = ""
For Each m As System.Reflection.PropertyInfo In objName.GetType().GetProperties()
If m.CanRead Then
If m.PropertyType.Name = "String" Then
CollName = m.Name
Dim CollVal = CallByName(objName, CollName, CallType.Get)
If CollVal = "" Then
objName.CollName = Nothing 'this is the tricky bit
End If
End If
End If
Next
End Sub
它明显中断的位是 objName.CollName = Nothing,因为它会说该对象没有名为 CollName 的成员,我不确定是否有强制代码的方法将 CollName 计算为其值(例如 SPARE8 而不是字符串 "CollName")
最后我选择了这个
UpLB_request_Items.Spare4 = Strings.Replace(Convert.ToString(SourceDataSet.Tables(0).Rows(i)(colSPARE4)), "", Nothing)
我有一些代码可以填充 VB.NET 中的 SOAP 请求。我从 SQL 查询中获取数据,并通过对象成员 运行 来填充每个数据。我正在尝试找到一种快速(ish)方法来在成员为空时不提供该成员,而不是在应用它之前检查每个值。由于 SQL 数据首先来自管道分隔文件,我们永远不会得到 NULL,只是在 SOAP 请求中作为“”发送的空单元格。
有没有办法使用变量而不是其字面名称来定义对象成员?
UpLB_request_Items.Spare8 = Convert.ToString(SourceDataSet.tables(0).Rows(i)(colSPARE8))
UpLB_request_Items.Spare9 = Convert.ToString(SourceDataSet.tables(0).Rows(i)(colSPARE9))
UpLB_request_Items.Spare10 = Convert.ToString(SourceDataSet.tables(0).Rows(i)(colSPARE10))
Call IterateObject(UpLB_request_Items)
所以这会用 SQL 数据 (SourceDataSet) 中的值填充每个成员,然后我可以将完成的对象发送到 Sub 以在我实际将其发送到 web 服务之前检查每个值
Sub IterateObject(objName)
Dim CollName = ""
For Each m As System.Reflection.PropertyInfo In objName.GetType().GetProperties()
If m.CanRead Then
If m.PropertyType.Name = "String" Then
CollName = m.Name
Dim CollVal = CallByName(objName, CollName, CallType.Get)
If CollVal = "" Then
objName.CollName = Nothing 'this is the tricky bit
End If
End If
End If
Next
End Sub
它明显中断的位是 objName.CollName = Nothing,因为它会说该对象没有名为 CollName 的成员,我不确定是否有强制代码的方法将 CollName 计算为其值(例如 SPARE8 而不是字符串 "CollName")
最后我选择了这个
UpLB_request_Items.Spare4 = Strings.Replace(Convert.ToString(SourceDataSet.Tables(0).Rows(i)(colSPARE4)), "", Nothing)