Passing parameter to asmx web-service in Postman

12,752

Add the following to the <system.web> block in Web.config file:

<webServices>
      <protocols>
        <add name="HttpGet" />
        <add name="HttpPost" />
      </protocols>
</webServices>

Well the error image in the question has the request method as POST in Postman and the Source code has UseHttpGet = true for the WebMethod.

Share:
12,752
VIVEK RAMASAMY
Author by

VIVEK RAMASAMY

Updated on June 04, 2022

Comments

  • VIVEK RAMASAMY
    VIVEK RAMASAMY almost 2 years

    I have created a asmx web-service like below:

    [WebMethod]
    [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
    public void GetEmployeesJSONByID(int sId)
    {
      try {
        string sResult = string.Empty;
        List<Employee> lstEmp = new List<Employee>();
    
        List<Employee> lstEmpNew = new List<Employee>();
    
        lstEmp.Add(new Employee { Id = 101, Name = "Nitin", Salary = 10000 });
        lstEmp.Add(new Employee { Id = 102, Name = "Dinesh", Salary = 20000 });
    
        switch (sId) {
          case 101: 
            lstEmpNew.Add(new Employee { Id = 101, Name = "Nitin", Salary = 10000 });
             break;
           case 102:
             lstEmpNew.Add(new Employee { Id = 102, Name = "Dinesh", Salary = 20000 });
             break;
           default:
             break;
         }
         JavaScriptSerializer js = new JavaScriptSerializer();
         sResult = js.Serialize(lstEmpNew);
    
         Context.Response.Write(sResult);
       } catch (Exception ex) {
         Context.Response.Write(ex.Message.ToString());
       }
     }
    

    I want to test this web-service via Postman. So I deployed in my local IIS and in the postman like below:

    enter image description here

    In the URL I given as

    http://XXXXXX/SampleWebService/Service.asmx/GetEmployeesJSONByID?sId=101
    

    I am getting the Request Format is invalid. How to pass this sId in the postman to test this webservice?

    • wazz
      wazz almost 6 years
      Is webservices defined in web.config to use HttpGet?
    • VIVEK RAMASAMY
      VIVEK RAMASAMY almost 6 years
      Yes, we have defined that too
  • VIVEK RAMASAMY
    VIVEK RAMASAMY almost 6 years
    these protocols i already added in the config file. Actually it is Get Method, so i changed the POST to GET in postman and it worked as expected. Thanks for the suggestion.
  • VIVEK RAMASAMY
    VIVEK RAMASAMY almost 6 years