locked
How to I send data to WebService RRS feed

  • Question

  • User1989204087 posted

    Hi, Have not been using webservice much.  How do I send data ( String or other dataType) to webservice ?  The data is from  a ListBox, so I need to send data in a loop fashion.

    How to create such web service? Would appreciate if you can provide some samples ,references or tutorial.

     

    Thanks

    Sunday, September 15, 2013 9:19 PM

Answers

  • User-37275327 posted

    How to create such web service?  

    Pass the datasource of the listbox to the web service.

    http://msdn.microsoft.com/en-us/library/s5xy331f%28v=vs.71%29.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 16, 2013 5:25 AM
  • User-488622176 posted

    Do not call the webservice in a loop, it will kill performance.

    Get the items from the listbox in a List<T> (where T can be int, String, ...)

    Create a webservice with method taking the list as input, and call the webservice.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 16, 2013 10:04 AM
  • User260886948 posted

    Hi,

    It seems that you want to use the data in listbox then send it to the webservice, if I do not misunderstand you, please try to refer to the following example:

    In the asmx:

    public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public Boolean getlistbox(List<string> ss)
            {
                if (ss.Contains("aa"))
                    return true;
                else return false;
             
            }
        }

    In the aspx(client):

     <form id="form1" runat="server">
        <div>
            <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem>aa</asp:ListItem>
                <asp:ListItem>bb</asp:ListItem>
            </asp:ListBox>
        </div>
     </form>

    In the .cs(client):

     List<string> list = (from p in ListBox1.Items.Cast<ListItem>() select p.Value).ToList();
         
     ServiceReference3.ArrayOfString ss = new ServiceReference3.ArrayOfString();
     ss.AddRange(list);
              
     ServiceReference3.WebService1SoapClient client = new ServiceReference3.WebService1SoapClient();
     Response.Write(client.getlistbox(ss));


    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 17, 2013 1:55 AM

All replies

  • User-37275327 posted

    How to create such web service?  

    Pass the datasource of the listbox to the web service.

    http://msdn.microsoft.com/en-us/library/s5xy331f%28v=vs.71%29.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 16, 2013 5:25 AM
  • User-488622176 posted

    Do not call the webservice in a loop, it will kill performance.

    Get the items from the listbox in a List<T> (where T can be int, String, ...)

    Create a webservice with method taking the list as input, and call the webservice.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 16, 2013 10:04 AM
  • User260886948 posted

    Hi,

    It seems that you want to use the data in listbox then send it to the webservice, if I do not misunderstand you, please try to refer to the following example:

    In the asmx:

    public class WebService1 : System.Web.Services.WebService
        {
            [WebMethod]
            public Boolean getlistbox(List<string> ss)
            {
                if (ss.Contains("aa"))
                    return true;
                else return false;
             
            }
        }

    In the aspx(client):

     <form id="form1" runat="server">
        <div>
            <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem>aa</asp:ListItem>
                <asp:ListItem>bb</asp:ListItem>
            </asp:ListBox>
        </div>
     </form>

    In the .cs(client):

     List<string> list = (from p in ListBox1.Items.Cast<ListItem>() select p.Value).ToList();
         
     ServiceReference3.ArrayOfString ss = new ServiceReference3.ArrayOfString();
     ss.AddRange(list);
              
     ServiceReference3.WebService1SoapClient client = new ServiceReference3.WebService1SoapClient();
     Response.Write(client.getlistbox(ss));


    Best Regards.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 17, 2013 1:55 AM