Solved

Calling a Web Service

Posted on 2014-09-18
1
128 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
Comment Utility
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now