Solved

Calling a Web Service

Posted on 2014-09-18
1
133 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
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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

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.
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

856 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