help with c# webservice

vanillathunder722

Active Member
Joined
Jan 14, 2011
Messages
66
Reaction score
0
Location
durban
alright, basically i've created a webservice with a method that will bubblesort 5 numbers. It will get the 5 numbers from a website that will connect to that webservice. The problem is how do i get the result and basically display them to the website in the form of labels?

Will have 5 labels to display each of those 5 numbers once they have been bubblesorted.

thanks
 
so you have connected to the webservice to pass it the numbers? and just want to know the result? or you havent connected to the webservice at all via the website?
 
The webservice will respond with anything you'd like. Depending on the complexity, I usually use JSON. However, for responding with 5 numbers, just push them back as a comma-delimited string. Then on the website's end, split them into an array and display them where the labels are.
 
hope this helps

OK. So i was bored with what i was doing so i quickly made this simple sample.

as i don't have all the details of what you what to do (code wise)

this is not fool proof :)

basically what this does is sending an int[] list to the web-service
and returns the sorted list.

i know you wanted to add the items to labels but i just didn't feel like it :whistle:
you can always modify the for loop to have it do what you want.

website default page
Code:
public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
     
            // created a basic list of integers //
    
             int[] Intlist_sent = {1,8,2,4,8,3,4,6};
    
              // connection to Local Servce //
    
             localhost.Service webservice = new localhost.Service();
    
            //get list back after passing list//
       
            int[] intlist_returned = webservice.BubbleSort(Intlist_sent);
         
          // checkes the returning list array and adds it to the Listbox //
        
             for (int i = 0; i < intlist_returned.Length; i++)
            {
                ListBox1.Items.Add(intlist_returned[i].ToString());

             }
        }
    }

web-service web method
Code:
  [WebMethod]
      public int[] BubbleSort (int[] list)
{
    for (int i = 0; i < list.Length; i++)
    {
        for (int j = 0; j < list.Length - i - 1; j++)
        {
            if(list [j] > list [j + 1])
            {
                int Temp = list [j];
                list [j] = list [j + 1];
                list [j + 1] = Temp;
            }
        }
    }
    return list;
}

output
Code:
1
2
3
4
4
6
8
8
 
Last edited:
lol at being bored ... though with a vague question like that I wonder if the op used Google
 
lol thanks for all your help guys. @death192 I just woke up now so I'll try out that code now now after breakfast, let you know later if it works :)
 
Top
Sign up to the MyBroadband newsletter
X