Solved

Calling a Web Service

Posted on 2014-09-18
1
137 Views
Last Modified: 2014-09-19
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
Comment
Question by:RecipeDan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 22

Accepted Solution

by:
Ivo Stoykov earned 500 total points
ID: 40330334
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

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question