C# WebAPI Array issue

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
LVL 2
lankapalaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
C# WebAPI Array issue
I'm trying send to using SOAP
Huh? Web API doesn't deal with SOAP (generally speaking).
0
lankapalaAuthor Commented:
ok, Any idea what is the issue
0
lankapalaAuthor Commented:
I found the reason. it's need initililized the class before the loop.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The 7 Worst Nightmares of a Sysadmin

Fear not! To defend your business’ IT systems we’re going to shine a light on the seven most sinister terrors that haunt sysadmins. That way you can be sure there’s nothing in your stack waiting to go bump in the night.

Kelvin McDanielSr. DeveloperCommented:
As written, that wasn’t the problem. In your OP all you ever requested from the reader was the OfferHeaderID value.
0
lankapalaAuthor 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
0
Kelvin McDanielSr. DeveloperCommented:
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!
0
lankapalaAuthor 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.
0
lankapalaAuthor Commented:
I found the issue
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.