INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Webservice array initializer

Webservice array initializer

(OP)
Hi I'm successfully making a Webservice request with the inclusion of the statements below.

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

I am assuming that FreightShipmentLineItem is an object you have created, correct?
If so, can you post the definition of that object?

RE: Webservice array initializer

(OP)

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 -->

<xs:complexType name="FreightShipmentLineItem">
        <xs:annotation>
          <xs:documentation>Description of an individual commodity or class of content in a shipment.</xs:documentation>
        </xs:annotation>
        <xs:sequence>
          <xs:element name="FreightClass" type="ns:FreightClassType" minOccurs="0">
            <xs:annotation>
              <xs:documentation>Freight class for this line item.</xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="Packaging" type="ns:PhysicalPackagingType" minOccurs="0">
            <xs:annotation>
              <xs:documentation>Specification of handling-unit packaging for this commodity or class line.</xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="Pieces" type="xs:nonNegativeInteger" minOccurs="0">
            <xs:annotation>
              <xs:documentation>Number of pieces for this commodity or class line.</xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="Description" type="xs:string" minOccurs="0">
            <xs:annotation>
              <xs:documentation>Customer-provided description for this commodity or class line.</xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="Weight" type="ns:Weight" minOccurs="0">
            <xs:annotation>
              <xs:documentation>Weight for this commodity or class line.</xs:documentation>
            </xs:annotation>
          </xs:element>
          <xs:element name="Dimensions" type="ns:Dimensions" minOccurs="0"/>
          <xs:element name="Volume" type="ns:Volume" minOccurs="0">
            <xs:annotation>
              <xs:documentation>Volume (cubic measure) for this commodity or class line.</xs:documentation>
            </xs:annotation>
          </xs:element>
        </xs:sequence>
      </xs:complexType> 

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

Well
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

(OP)
Correct :)

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 -->

request.RequestedShipment.FreightShipmentDetail.LineItems = New FreightShipmentLineItem(1) {New FreightShipmentLineItem(), New FreightShipmentLineItem()} 


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 -->

request.RequestedShipment.FreightShipmentDetail.LineItems = New FreightShipmentLineItem(1) {New FreightShipmentLineItem(), 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



        request.RequestedShipment.FreightShipmentDetail.LineItems(1) = New FreightShipmentLineItem
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).FreightClass = FreightClassType.CLASS_065
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).FreightClassSpecified = True
        '
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Packaging = PhysicalPackagingType.SKID
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).PackagingSpecified = True
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Description = "Freight line item two "
        '
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Weight = New Weight()
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Weight.Units = WeightUnits.LB
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Weight.UnitsSpecified = True
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Weight.Value = (650)
        request.RequestedShipment.FreightShipmentDetail.LineItems(1).Weight.ValueSpecified = True 

RE: Webservice array initializer

Is there any reason you NEED to use an array? I would use a collection(or List) of the object you need to have. For example, will something like this work for you:
(I am writing this in VB, be we can convert it easily to C# if you need.

CODE

'Let's assume you only have one Detail item, but many LineItems
   Dim  shipmentDetail as New FreightShipmentDetail()
   Dim  lineItems as New List(Of FreightShipmentLineItem)
'Now  your loop.. you may need to change this..
   For Each dr as DataRow in dt.Rows  ''maybe this is a datatable of line items..  you need to adjust to your code
      Dim  lineItem as New FreightShipmentLineItem()
      lineItem.FreightClass = dr("FreightClass")
      lineItem.FreightClassSpecified = dr("FrieghtClassSpecified")
'''  continue for each property on the object.  You can also hard code values if you need
      lineItems.Add(lineItem)
   Next 
'All of your lineItems are now in a List, add that to the FreightShiptmentDetail object
   shipmentDetail.LineItems = lineItems
   shipmentDetail.anotherProperty = "Some Value"
''  ..etc 

RE: Webservice array initializer

(OP)
The array was presented in an example soap call from the fedex development center.
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

Good luck and please post back so I know how things are going

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close