C# WebAPI Array issue

lankapala
lankapala used Ask the Experts™
on
Hi, I'm trying send to using SOAP to data,but it's keep sending the same value. I created array ,but didn't work

My code
OMS.OfferOrdered oOfferOrdered = new OMS.OfferOrdered();
            newOrders.Offers = new OMS.OfferOrdered[TotalNumberLine];
            OMS.OfferIDHeader oOfferIDHeader = new OMS.OfferIDHeader();
            OMS.OfferID oOfferID = new OMS.OfferID();


  while (reader.Read())
                {

 newOrders.Offers[i].Offer.Header.ID = reader["OfferHeaderID"].ToString();
}

Open in new window


Web services  Code

  public partial class OfferOrdered : PMObject {
        
        private OfferID offerField;

}


public partial class OfferOrdered : PMObject {
 [System.Xml.Serialization.XmlArrayAttribute(Order=9)]
        public OfferOrdered[] Offers {
            get {
                return this.offersField;
            }
            set {
                this.offersField = value;
                this.RaisePropertyChanged("Offers");
            }
        }
}
public partial class OfferIDHeader : PMObject {
 [System.Xml.Serialization.XmlElementAttribute(Order=1)]
        public string ID {
            get {
                return this.idField;
            }
            set {
                this.idField = value;
                this.RaisePropertyChanged("ID");
            }
        }
}
 public OfferIDHeader Header {
            get {
                return this.headerField;
            }
            set {
                this.headerField = value;
                this.RaisePropertyChanged("Header");
            }
        }
}

Open in new window


Any idea much appreciated. Just want to know why is keep recording last number in the all the array.

For example

if in the order having ID 500,800,900.
It will keep saving in the array 900 for all the array[0],array[1] and  array[2]



MAny Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
kaufmedGlanced up at my screen and thought I had coded the Matrix...  Turns out, I just fell asleep on the keyboard.
Most Valuable Expert 2011
Top Expert 2015

Commented:
C# WebAPI Array issue
I'm trying send to using SOAP
Huh? Web API doesn't deal with SOAP (generally speaking).

Author

Commented:
ok, Any idea what is the issue
I found the reason. it's need initililized the class before the loop.
How to Generate Services Revenue the Easiest Way

This Tuesday! Learn key insights about modern cyber protection services & gain practical strategies to skyrocket business:

- What it takes to build a cloud service portfolio
- How to determine which services will help your unique business grow
- Various use-cases and examples

As written, that wasn’t the problem. In your OP all you ever requested from the reader was the OfferHeaderID value.

Author

Commented:
@Kelvin McDaniel:
if you know the answer , why you didn't help me.now to late.Anyway i found the answer.
I'll appreciate,if you show me how to do that or where is mistake.rather than commenting after that .
Many thanks
A couple of things:
1). I “didn’t help” you because I literally saw this question for the first time no more than 15 minutes ago. Regardless, my response has the help I would give — just not in code.

2). Experts don’t get paid for this; I’m literally in the middle of my workday morning “ritual” and I’m giving my time away for free... so be nice. :)

In your code you have the following:
while (reader.Read())
{
 newOrders.Offers[i].Offer.Header.ID = reader["OfferHeaderID"].ToString();
}

Open in new window


This line dictates what you are modifying on an object at a specified index (i) of that array:
newOrders.Offers[i].Offer.Header.ID = reader["OfferHeaderID"].ToString();

Open in new window


Your code does not show how you are incrementing i but that’s less of an issue because at least it is certainly a variable and in your OP you stated that your array is larger than one item. From what you’ve given us, nothing changes what you’re looking for from the reader; only the single value of OfferHeaderID is ever retrieved. You’ll need to use a variable instead of ”OfferHeaderID” if you want to get something else out of the reader.

Good Luck!

Author

Commented:
Thank you very much for reply
Sorry my mistake,not putting whole code.

Yes, there is i increment.
No it's not larger than.

Author

Commented:
I found the issue

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial