• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

List Array in Web Service

I have the following code which I can use to get one offs of each item.  But if I would also receive order information and there could be X number of products how would I modify this and how would I then retreive those in my code?
public class Service1 : System.Web.Services.WebService
    {
 
        [WebMethod]
        public string InsertOrder(
              string CustomerID
            , string FirstName
            , string LastName
            , string Address1
            , string Address2
            , string Address3
            , string City
            , string County
            , string Postcode
            , string Telephone
            , string Mobile
            , string Email
            , string dFirstName
            , string dLastName
            , string dAddress1
            , string dAddress2
            , string dAddress3
            , string dCity
            , string dCounty
            , string dPostCode
            )
        {
        /// MyCode
       }
}

Open in new window

0
andrewmilner
Asked:
andrewmilner
  • 3
  • 2
1 Solution
 
GiftsonDJohnCommented:
Hi,

Use like this.


public class Service1 : System.Web.Services.WebService
    {
 
        [WebMethod]
        public string InsertOrder(List<OrderDetail> orders)
        {
        /// MyCode
        }
}
 
[Serializable]
public class OrderDetail
{
 public string CustomerID;
 public string string FirstName;
 public string LastName;
 public string Address1;
 public string Address2;
 public string Address3;
 public string City;
 public string County;
 public string Postcode;
 public string Telephone;
 public string Mobile;
 public string Email;
 public string dFirstName;
 public string dLastName;
 public string dAddress1;
 public string dAddress2;
 public string dAddress3;
 public string dCity;
 public string dCounty;
 public string dPostCode;
}

Open in new window

0
 
andrewmilnerAuthor Commented:
Thanks.

Then how would I access / loop through each item in the code?
0
 
GiftsonDJohnCommented:
[WebMethod]
        public string InsertOrder(List<OrderDetail> orders)
        {
               foreach(OrderDetail order in orders)
              {
              }
        }
0
 
andrewmilnerAuthor Commented:
Many Thanks for your help.

How would I go about inserting to the WebService.  I have the code below so far but I guess I would need to define a List on the sending end and then somehow get this into the WebService call.
            string result = Service1.InsertOrder(
                 "CustomerID",
                 "FirstName",
                 "LastName",
                 "Address1",
                 "Address2",
                 "Address3",
                 "City",
                 "County",
                 "Postcode",
                 "Telephone",
                 "Mobile",
                 "Email",
                 "dFirstName",
                 "dLastName",
                 "dAddress1",
                 "dAddress2",
                 "dAddress3",
                 "dCity",
                 "dCounty",
                 "dPostCode"
                 );

Open in new window

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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