• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 108
  • Last Modified:

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
0
lankapala
Asked:
lankapala
  • 5
  • 2
1 Solution
 
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
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
Kelvin McDanielSr. Developer/ConsultantCommented:
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. Developer/ConsultantCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now