Webservice array initializer
Webservice array initializer
(OP)
Hi I'm successfully making a Webservice request with the inclusion of the statements below.
I initialize the array using request.RequestedShipment.FreightShipmentDetail.LineItems = New FreightShipmentLineItem(0) {New FreightShipmentLineItem()}
Which works when there is only 1 line item/
I Can't seem to figure out how to initialize it to pass more line item (up to 5)
I plan on pulling the line items using a dataset and iterating through it to populate the array with multiple line items. The dataset is easy to do.
I've set the boundary to 4 = New FreightShipmentLineItem(3) [4 items on a zero based index] but then i get an error "array initializer missing 4 elements"
Thanks
-dan
CODE --> ASP.net
request.RequestedShipment.FreightShipmentDetail.LineItems = New FreightShipmentLineItem(0) {New FreightShipmentLineItem()} request.RequestedShipment.FreightShipmentDetail.LineItems(0).FreightClass = FreightClassType.CLASS_050 request.RequestedShipment.FreightShipmentDetail.LineItems(0).FreightClassSpecified = True request.RequestedShipment.FreightShipmentDetail.LineItems(0).Packaging = PhysicalPackagingType.SKID request.RequestedShipment.FreightShipmentDetail.LineItems(0).PackagingSpecified = True request.RequestedShipment.FreightShipmentDetail.LineItems(0).Description = "Freight line item 0NE" ' request.RequestedShipment.FreightShipmentDetail.LineItems(0).Weight = New Weight() request.RequestedShipment.FreightShipmentDetail.LineItems(0).Weight.Units = WeightUnits.LB request.RequestedShipment.FreightShipmentDetail.LineItems(0).Weight.UnitsSpecified = True request.RequestedShipment.FreightShipmentDetail.LineItems(0).Weight.Value = (500) request.RequestedShipment.FreightShipmentDetail.LineItems(0).Weight.ValueSpecified = True
I initialize the array using request.RequestedShipment.FreightShipmentDetail.LineItems = New FreightShipmentLineItem(0) {New FreightShipmentLineItem()}
Which works when there is only 1 line item/
I Can't seem to figure out how to initialize it to pass more line item (up to 5)
I plan on pulling the line items using a dataset and iterating through it to populate the array with multiple line items. The dataset is easy to do.
I've set the boundary to 4 = New FreightShipmentLineItem(3) [4 items on a zero based index] but then i get an error "array initializer missing 4 elements"
Thanks
-dan
RE: Webservice array initializer
If so, can you post the definition of that object?
RE: Webservice array initializer
JB
I downloaded a wsdl and made a proxy class using wsdl.exe
FreightShipmentLineItem is a class from with in. I'm not sure what you mean by its definition. I'm kind of new at this type request. The only thing I'm seeing is:
<xs:element name="LineItems" type="ns:FreightShipmentLineItem" minOccurs="0" maxOccurs="unbounded">
CODE -->
The XSD file is here if it will help. Just search for "Lineitems" Right below the lineitems it the XML for ns:FreightShipmentLineItem
Link
RE: Webservice array initializer
FreightShipmentDetail and
FreightShipmentLineItem
must be objects, because you are newing them up.. correct? Each of those has a definition, a class file that defines them.(Properties, methods, events)
I am assuming the FreightShipmentDetail object has a property called LineItems, which is a colletion of FreightShipmentLineItem(s), correct?
RE: Webservice array initializer
Got this from the object browser.
Private lineItemsField() As RateWebServiceClient.RateWebReference.FreightShipmentLineItem
Member of RateWebServiceClient.RateWebReference.FreightShipmentDetail
Also: If I set the array boundy to 1 and modify the top line above to read
CODE -->
The array actually picks stores (success!) the second line item. I'll know how many line items there will be based on a returned dataset row count. There has to be a way to initialize the array without having a bunch of elseif rowcaount = statements.
CODE -->
RE: Webservice array initializer
(I am writing this in VB, be we can convert it easily to C# if you need.
CODE
RE: Webservice array initializer
I sure give the List a tryout :). Might be a bit before I can test it but I'll post the results here. VB is fine with me as that's my primary & favorite language.
Thank you very much
-dan
RE: Webservice array initializer