|
-
Jun 14th, 2004, 10:43 AM
#1
Thread Starter
I wonder how many charact
Return two-dimensional string from .net webservice
I'm having difficulties with this...
I need to return a two-dimensional string array from a web service....
It seems simple enough...
VB Code:
<WebMethod> Public Function ReturnMultiDimArray() As String()()
Dim y As String()
Dim z As String()
Dim x As String()() = New String()() {y, z}
Return x
End Function
However, I need to populate the two dimensions (y and z) dynamically from a datareader.
So I tried using ( ) arrayLists for y and z, and using to arraylist.ToArray method, but of course, I get an invalid cast exception when trying to build the 2-d string array:
VB Code:
Dim x As String()() = New String()() {y.ToArray, z.ToArray}
I saw StringDictionary, but that doesn't serialize... and I don't want to waste hours figuring out to implement Iserializable and implenets getObject....
Any ideas?
-
Jun 14th, 2004, 11:55 AM
#2
Thread Starter
I wonder how many charact
Well, I didn't solve the problem as I intended, however, I was able to return the data via XML, so I guess that is a feasible solution. I still would like to know if anyone had an easier way:
VB Code:
Imports System.Xml.Serialization
...
Sqlconnection1.Open()
dr = Sqlcommand1.ExecuteReader(CommandBehavior.CloseConnection)
While dr.Read
x.Add(New SubmissionItem(dr(0), dr(1)))
End While
dr.Close()
Dim sw As System.io.StringWriter = New System.IO.StringWriter
Dim s As XmlSerializer = New XmlSerializer(GetType(SubmissionTypeArrayList))
s.Serialize(sw, x)
Return x
Classes created to use code above:
VB Code:
Imports System.Xml.Serialization
<XmlRoot("SubmissionTypes")> Public Class SubmissionTypeArrayList
Private _SubmissionList = New ArrayList
Public CarsArrayList()
<XmlArray("SubmissionList"), _
XmlArrayItem("SubmissionTypeItem", GetType(SubmissionItem))> _
Public Property SubmissionCollection() As ArrayList
Get
Return _SubmissionList
End Get
Set(ByVal Value As ArrayList)
_SubmissionList = Value
End Set
End Property
Public Property Submission(ByVal index As Integer)
Get
Return _SubmissionList(index)
End Get
Set(ByVal Value)
If index > _SubmissionList.count - 1 Then
_SubmissionList.add(Value)
Else
_SubmissionList(index) = Value
End If
End Set
End Property
Public Sub Add(ByVal s As SubmissionItem)
_SubmissionList.add(s)
End Sub
End Class
Public Class SubmissionItem
<XmlElement("fksubmission")> Public fkSubmission As String
<XmlElement("submissiontype")> Public SubmissionType As String
Public Sub New()
End Sub
Public Sub New(ByVal s1 As String, ByVal s2 As String)
fkSubmission = s1
SubmissionType = s2
End Sub
End Class
-
Jun 14th, 2004, 12:11 PM
#3
Try this...
VB Code:
Dim x As String()() = New String()() {y.ToArray(GetType(String)), z.ToArray(GetType(String))}
From your first attempt, that is.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 14th, 2004, 12:55 PM
#4
Thread Starter
I wonder how many charact
Thanks crpt, that solves the initial request.
Of course, now I have to decide which would be easier to populate a dropdownbox in old ASP from:
returning a 2-d jagged string array
VB Code:
- <ArrayOfString>
<string>1</string>
<string>2</string>
</ArrayOfString>
- <ArrayOfString>
<string>Injury</string>
<string>Suspicious Activity</string>
</ArrayOfString>
</ArrayOfArrayOfString>
Or the custom class implementation:
VB Code:
<SubmissionTypeItem>
<fksubmission>1</fksubmission>
<submissiontype>Injury</submissiontype>
</SubmissionTypeItem>
- <SubmissionTypeItem>
<fksubmission>2</fksubmission>
<submissiontype>Suspicious Activity</submissiontype>
</SubmissionTypeItem>
</SubmissionList>
???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|