Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 148
  • Last Modified:

Calling a Web Service

I am trying to call a webservice from a listbox. I keep getting the error message Webservice unreachable

        <script type="text/javascript">
            function serviceCall() {
                var listBox = document.getElementById("<%= PersonList.ClientID %>").va;
            if (listBox.length > 0) {
                $.ajax({
                    type: "POST",
                    url: 'WebService1.asmx/TestlistBox',
                    data: "{'data':'" + listBox + "'}",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) {
                        $("#Result").html(msg.d);
                    },
                    error: function (e) {
                        $("#Result").html("WebSerivce unreachable");
                    }
                });
            }
        }
    </script>

Open in new window

<asp:ListBox ID="PersonList" Width="300px" SelectionMode="Single" Height="300px" runat="server" />

Open in new window

    /// <summary>
    /// Summary description for WebService1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class WebService1 : System.Web.Services.WebService
    {

        [WebMethod]
        public string TestlistBox(String data)
        {
            return data;
        }
    }

Open in new window

0
RecipeDan
Asked:
RecipeDan
1 Solution
 
Ivo StoykovCommented:
Hi

your TestlistBox method expects a string as a parameter, so try
$.ajax({
                    type: "POST",
                    url: 'WebService1.asmx/TestlistBox',
                    data: 'data=' + listBox,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

Open in new window

HTH
Ivo Stoykov
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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