Solved

Calling a Web Service

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Adding a Li to a UL after a specified Li contents 2 46
Name space syntax error 12 43
Wav problem 4 16
ASP.net show message while code is running 3 9
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…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn how to dynamically set the form action using jQuery.
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…

895 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

14 Experts available now in Live!

Get 1:1 Help Now