Arrays 索引超出范围-通过.NET传递WCF上的列表值
我在VB.NET中有以下代码:Arrays 索引超出范围-通过.NET传递WCF上的列表值,arrays,vb.net,wcf,Arrays,Vb.net,Wcf,我在VB.NET中有以下代码: 我的合同: <ServiceContract(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name)> Public Interface IMyCoolInterface <OperationContract()> Function fetchDataBaseNameByParam(QueryInfo As Database) As Database En
我的合同:
<ServiceContract(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name)>
Public Interface IMyCoolInterface
<OperationContract()>
Function fetchDataBaseNameByParam(QueryInfo As Database) As Database
End Interface
<DataContract(Name:="DatabaseNameContract", Namespace:=Constants.GlobalNamespace), KnownType(GetType(List(Of String)))>
Public Class Database
<DataMember(Name:="ArrayOfParams")>
Public ListOfParams As List(Of String)
<DataMember(Name:="DatabaseNames")>
Public DatabaseNames As ArrayList
End Class
<ServiceBehavior(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name, ConfigurationName:="GetCatalogDBC", IncludeExceptionDetailInFaults:=True)>
Public Class MyCoolClass
Implements IMyCoolInterface
Private conString As String = "Data Source=myDBServer;User ID=user;Password=pass;"
Property connectionString() As String
Get
Return conString
End Get
Set(ByVal Value As String)
conString = Value
End Set
End Property
Private queryString As String
Property Query() As String
Get
Return queryString
End Get
Set(ByVal Value As String)
queryString = Value
End Set
End Property
Public Sub New()
End Sub
Public Function fetchDataBaseNameByParam(ByVal QueryInfo As Database) As Database Implements IMyCoolInterface.fetchDataBaseNameByParam
Dim myConnection As TdConnection = New TdConnection()
myConnection.ConnectionString = Me.connectionString()
Dim myCommand As TdCommand = myConnection.CreateCommand()
Me.Query() = "SELECT DatabaseName FROM DBC.Databases WHERE UPPER(RTRIM(DatabaseName)) like any( '" + QueryInfo.ListOfParams.Item(0).ToString + "%_T') group by DatabaseName;"
myCommand.CommandText = Me.Query()
Dim myReader As TdDataReader
Try
myConnection.Open()
myReader = myCommand.ExecuteReader()
While myReader.Read()
QueryInfo.DatabaseNames.Add(myReader.Item("DatabaseName").ToString)
End While
myReader.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
Try
myConnection.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
Return QueryInfo
End Function
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://iis-mrd.pncbank.com/GetTeradataDBC" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<soapenv:Header/>
<soapenv:Body>
<get:fetchDataBaseNameByParam>
<!--Optional:-->
<get:QueryInfo>
<!--Optional:-->
<get:ArrayOfParams>
<arr:string>?</arr:string>
</get:ArrayOfParams>
<get:DatabaseNames>
<!--Zero or more repetitions:-->
<arr:anyType>?</arr:anyType>
</get:DatabaseNames>
</get:QueryInfo>
</get:fetchDataBaseNameByParam>
</soapenv:Body>
</soapenv:Envelope>
公共接口IMyCoolInterface
函数fetchDataBaseNameByParam(QueryInfo作为数据库)作为数据库
端接口
公共类数据库
公共列表参数作为列表(字符串)
作为ArrayList的公共数据库名
末级
实施:
<ServiceContract(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name)>
Public Interface IMyCoolInterface
<OperationContract()>
Function fetchDataBaseNameByParam(QueryInfo As Database) As Database
End Interface
<DataContract(Name:="DatabaseNameContract", Namespace:=Constants.GlobalNamespace), KnownType(GetType(List(Of String)))>
Public Class Database
<DataMember(Name:="ArrayOfParams")>
Public ListOfParams As List(Of String)
<DataMember(Name:="DatabaseNames")>
Public DatabaseNames As ArrayList
End Class
<ServiceBehavior(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name, ConfigurationName:="GetCatalogDBC", IncludeExceptionDetailInFaults:=True)>
Public Class MyCoolClass
Implements IMyCoolInterface
Private conString As String = "Data Source=myDBServer;User ID=user;Password=pass;"
Property connectionString() As String
Get
Return conString
End Get
Set(ByVal Value As String)
conString = Value
End Set
End Property
Private queryString As String
Property Query() As String
Get
Return queryString
End Get
Set(ByVal Value As String)
queryString = Value
End Set
End Property
Public Sub New()
End Sub
Public Function fetchDataBaseNameByParam(ByVal QueryInfo As Database) As Database Implements IMyCoolInterface.fetchDataBaseNameByParam
Dim myConnection As TdConnection = New TdConnection()
myConnection.ConnectionString = Me.connectionString()
Dim myCommand As TdCommand = myConnection.CreateCommand()
Me.Query() = "SELECT DatabaseName FROM DBC.Databases WHERE UPPER(RTRIM(DatabaseName)) like any( '" + QueryInfo.ListOfParams.Item(0).ToString + "%_T') group by DatabaseName;"
myCommand.CommandText = Me.Query()
Dim myReader As TdDataReader
Try
myConnection.Open()
myReader = myCommand.ExecuteReader()
While myReader.Read()
QueryInfo.DatabaseNames.Add(myReader.Item("DatabaseName").ToString)
End While
myReader.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
Try
myConnection.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
Return QueryInfo
End Function
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://iis-mrd.pncbank.com/GetTeradataDBC" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<soapenv:Header/>
<soapenv:Body>
<get:fetchDataBaseNameByParam>
<!--Optional:-->
<get:QueryInfo>
<!--Optional:-->
<get:ArrayOfParams>
<arr:string>?</arr:string>
</get:ArrayOfParams>
<get:DatabaseNames>
<!--Zero or more repetitions:-->
<arr:anyType>?</arr:anyType>
</get:DatabaseNames>
</get:QueryInfo>
</get:fetchDataBaseNameByParam>
</soapenv:Body>
</soapenv:Envelope>
公共类
实现imycool接口
私有解析为String=“数据源=myDBServer;用户ID=用户;密码=通行证;”
属性connectionString()作为字符串
得到
回归分析
结束
设置(ByVal值作为字符串)
构造=值
端集
端属性
作为字符串的私有查询字符串
属性查询()作为字符串
得到
返回查询字符串
结束
设置(ByVal值作为字符串)
查询字符串=值
端集
端属性
公共分新()
端接头
公共函数fetchDataBaseNameByParam(ByVal QueryInfo作为数据库)作为数据库实现IMyCoolInterface.fetchDataBaseNameByParam
Dim myConnection作为TdConnection=新的TdConnection()
myConnection.ConnectionString=Me.ConnectionString()
将myCommand作为TdCommand=myConnection.CreateCommand()进行调整
Me.Query()=“从DBC.DatabaseName中选择DatabaseName,其中UPPER(RTRIM(DatabaseName))与任何(‘“+QueryInfo.ListoParams.Item(0).ToString+“%”按DatabaseName分组;”
myCommand.CommandText=Me.Query()
将myReader设置为TdDataReader
尝试
myConnection.Open()
myReader=myCommand.ExecuteReader()
而myReader.Read()
QueryInfo.DatabaseNames.Add(myReader.Item(“DatabaseName”).ToString)
结束时
myReader.Close()
特例
控制台写入线(例如StackTrace)
结束尝试
尝试
myConnection.Close()
特例
控制台写入线(例如StackTrace)
结束尝试
返回查询信息
端函数
运行此命令,将生成以下SOAP请求:
<ServiceContract(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name)>
Public Interface IMyCoolInterface
<OperationContract()>
Function fetchDataBaseNameByParam(QueryInfo As Database) As Database
End Interface
<DataContract(Name:="DatabaseNameContract", Namespace:=Constants.GlobalNamespace), KnownType(GetType(List(Of String)))>
Public Class Database
<DataMember(Name:="ArrayOfParams")>
Public ListOfParams As List(Of String)
<DataMember(Name:="DatabaseNames")>
Public DatabaseNames As ArrayList
End Class
<ServiceBehavior(Namespace:=Constants.GlobalNamespace, Name:=Constants.Name, ConfigurationName:="GetCatalogDBC", IncludeExceptionDetailInFaults:=True)>
Public Class MyCoolClass
Implements IMyCoolInterface
Private conString As String = "Data Source=myDBServer;User ID=user;Password=pass;"
Property connectionString() As String
Get
Return conString
End Get
Set(ByVal Value As String)
conString = Value
End Set
End Property
Private queryString As String
Property Query() As String
Get
Return queryString
End Get
Set(ByVal Value As String)
queryString = Value
End Set
End Property
Public Sub New()
End Sub
Public Function fetchDataBaseNameByParam(ByVal QueryInfo As Database) As Database Implements IMyCoolInterface.fetchDataBaseNameByParam
Dim myConnection As TdConnection = New TdConnection()
myConnection.ConnectionString = Me.connectionString()
Dim myCommand As TdCommand = myConnection.CreateCommand()
Me.Query() = "SELECT DatabaseName FROM DBC.Databases WHERE UPPER(RTRIM(DatabaseName)) like any( '" + QueryInfo.ListOfParams.Item(0).ToString + "%_T') group by DatabaseName;"
myCommand.CommandText = Me.Query()
Dim myReader As TdDataReader
Try
myConnection.Open()
myReader = myCommand.ExecuteReader()
While myReader.Read()
QueryInfo.DatabaseNames.Add(myReader.Item("DatabaseName").ToString)
End While
myReader.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
Try
myConnection.Close()
Catch ex As Exception
Console.WriteLine(ex.StackTrace)
End Try
Return QueryInfo
End Function
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:get="http://iis-mrd.pncbank.com/GetTeradataDBC" xmlns:arr="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<soapenv:Header/>
<soapenv:Body>
<get:fetchDataBaseNameByParam>
<!--Optional:-->
<get:QueryInfo>
<!--Optional:-->
<get:ArrayOfParams>
<arr:string>?</arr:string>
</get:ArrayOfParams>
<get:DatabaseNames>
<!--Zero or more repetitions:-->
<arr:anyType>?</arr:anyType>
</get:DatabaseNames>
</get:QueryInfo>
</get:fetchDataBaseNameByParam>
</soapenv:Body>
</soapenv:Envelope>
?
?
但是当我尝试发送一个参数时,比如:PARAM
,
我得到以下错误,好像列表是空的:
<Message>Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index</Message>
索引超出范围。必须为非负数且小于集合的大小。
参数名称:索引
通过将列表(字符串)更改为字符串,我能够获得成功的响应,但稍后我将发送多个值,因此我需要某种数组。。有什么帮助吗?通过创建一个wrap类修复了此问题,可能值得在此答案上展开以显示代码等。