Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help Using a Generic List with a Webservice Class

Status
Not open for further replies.

xcaliber2222

Programmer
Apr 10, 2008
70
US
Hello,

I am importing a generic list into a class to test a webservice:

Here is my TESTList class:

Imports System.Collections.Generic
<Serializable()> _
Public Class TESTList
Inherits List(Of TEST)
End Class

Here is my class for the Getters and Setters:

<Serializable()> _
Public Class TEST
Private _TESTNum As String
Private _Description As String
Private _PCSList As New PCSList

Public Property TESTNum() As String
Get
Return _TESTNum
End Get
Set(ByVal value As String)
_TESTNum = value
End Set
End Property
Public Property Description() As String
Get
Return _Description
End Get
Set(ByVal value As String)
_Description = value
End Set
End Property
Public Property PCSList() As PCSList
Get
Return _PCSList
End Get
Set(ByVal value As PCSList)
_PCSList = value
End Set
End Property
End Class

Here is my main test class that will fire on Page_Load:

Public Partial Class WebServiceTest
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim userName As String
Dim password As String
Dim vendorId As String
Dim jobId As Integer
Dim dttm As DateTime
Dim bol As String
Dim pieces As Integer
Dim Weight As Integer
Dim TESTList As VendorStatusWs.localhost.TEST()

userName = "proco1"
password = "33915"
vendorId = "proco"
jobId = 13661619
dttm = "2009-11-09T17:34:00-07:00"
bol = ""
pieces = 1
Weight = 45
'TESTList = "test"

Dim localwebservice As New localhost.VendorStatusWs
localwebservice.SetStatusDrop(userName, password, vendorId, jobId, dttm, bol, pieces, Weight, waitTime, TESTList)
End Sub
End Class

Could someone please show me how I would assign values to the variable TESTList?

I have an xml file that will doing an http post for these values:

<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:xsi=" xmlns:xsd=" xmlns:soap="<soap:Body>
<SetStatusTest xmlns="<UserName>testuser</UserName>
<Password>11111</Password>
<VendorID>test1</VendorID>
<JobID>12345678</JobID>
<Dttm>2009-11-09T17:34:00-07:00</Dttm>
<TESTList>
<TEST>
<TESTNum>4444-3333</TESTNum>
<Description>2 taped as 1</Description>
<PCSList>
<Weight>45</Weight>
</PCSList>
</TEST>
</TESTList>
<BOL></BOL>
<Pieces>1</Pieces>
<Weight>45</Weight>
</SetStatusTest>
</soap:Body>
</soap:Envelope>

I need to be able to step through my webservice class, and can do so now if the parms are all primitive types (string, integer, etc.)

The problem is when I try to add this generic list and it complains about it not being a 1-dimensional array. I need to be able to bring in this list because there may be more than one item in some cases and thought a generic list might be a good solution since I'm using VS2005.

Also, does it matter what order I'm reading in the parms? In my test class the TESTList is the last parm, but in the xml file it is in the middle somewhat.

Thank you very much to anyone who is taking the valuable time from your day to go through this. I would greatly appreciate any help on this, or even a better suggestion on reading in this list. It's for testing so it doesn't have to be perfect.

Thanks,
Alejandro
 
the error states the problem. you need (and should) pass an array not a generic list.

1st. there is not point in creating the class TESTList, or PCSList if you are not extending any sort of functionality. so delete this code.
2nd. point of a web service is heterogenous environments. so the client may not be able to create generic lists. After all generics are only found in .net.

the error is giving you the problem, and solution. pass an array rather than a list.
Code:
Test test = new Test();
test.TESTNum ="abc";
test.Description="foo"

List<Test> tests = new List<Test>();
tests.Add(test);

Test[] arrayOfTests = test;
this will also require some refactoring of the test class. you will need to convert PCSList to an array


Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top