ASP.Net, C#, JavaScript, jQuery, jQuery AJAX

How to Call ASMX WebService using HTTP GET with jQuery AJAX

By Default , WebMethod of ASMX is not allowed to be called using HTTP GET . So we will see a short demo here . Our HTML Markup of the aspx page is :

<asp:DropDownList ID="DropDownList2" runat="server" Width="150">
           <asp:ListItem Text="Select" Value="-1" />

We will fill this DropDown By calling ASMX Service’s WebMethod using HTTP GET with jQuery Ajax . My Client Code is like below :::

var DropDownList2 = $("#<%= DropDownList2.ClientID %>");

                type: "GET",
                url:"<%=ResolveUrl("~/MyWebService.asmx") %>/GetAllProjectName",
                contentType:"application/json; charset=utf-8",
                success: function(response){
                        var projects = response.d;
                            DropDownList2.append('<option value="'+ project.ProjectId +'" >' + project.ProjectName + '</option>');                        

My Server side code of the WebService is :::

         [ScriptMethod(UseHttpGet = true)]
         public List<ProjectOfEmployee> GetAllProjectName()
             return GetProjectName();   

Remember to add the below part of course

[ScriptMethod(UseHttpGet = true)]

Otherwise , It will give 500 Internal Server Error .

So now you are done 🙂 Cheers


How to consume asmx service in ASP.Net , C#

Below ,Its only a test application which will test the service is working fine or not .

Service.add_account__486ndh42929d_3wkqq_43kj3j2003ksinn_33 service = new add_account__486ndh42929d_3wkqq_43kj3j2003ksinn_33();
service.Url = "http://localhost:3379/add-account--486ndh42929d-3wkqq-43kj3j2003ksinn-33.asmx";
service.Timeout = 500 * 1000;
structCustomerAdder customerAdder = service.structCustomerAdderAddCustomer
(Service.enumTiers) Enum.Parse(typeof(enumTiers),ddlAppTier.SelectedItem.ToString()),