locked
ASP.NET Web Service RRS feed

  • Question

  • User2098295439 posted

    A Web Service is a software program that uses XML to exchange information with other software via common internet protocols. In a simple sense, Web Services are a way <g class="gr_ gr_5 gr-alert gr_gramm gr_inline_cards gr_run_anim Grammar multiReplace" id="5" data-gr-id="5">for</g> interacting with objects over the Internet.

    Friday, February 8, 2019 5:30 PM

All replies

  • User-1174608757 posted

    Hi Sixwares Tech Forum,

    In simple terms,Web Service (.asmx ) is a component that resides on a Web server and provides information and services to other network applications.

    Since it could provide asynchronous communications for XML applications that operate over a .NET communications framework, we often use it for ajax request.

    Here is a Web Service demo, I hope it could help you.

    aspx:

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
            $(function () {
                $("#Button1").click(function () {
                    var a = $("#TextBox1").val();
                    $.ajax({
                        type: "POST",
                        url: "WebService1.asmx/HelloWorld",
                        data: JSON.stringify({name:a}),
                        contentType: "application/json",  
                        datatype: "json", 
                        
                        success: function (msg) { alert(msg.d) }
    
                    })
    
                })
    
            })
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                name:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                <input id="Button1" type="button" value="button" />
            </div>
        </form>
    </body>
    </html>

    WebService1.asmx

    [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 HelloWorld(string name )
            {
                return "Hello World"+ name;
            }
        }

    It shows as below:

    Best Regards

    Wei Zhang

    Monday, February 11, 2019 6:19 AM