Click here to Skip to main content
15,888,461 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am a complete novice in .NET ASMX web services. Please dont mind if this seems like a silly question.

I created a simple ASMX web service which looks like this below:

<br />
    [WebService(Namespace = "http://tempuri.org/")]<br />
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]<br />
    [System.ComponentModel.ToolboxItem(false)]<br />
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. <br />
    [System.Web.Script.Services.ScriptService]<br />
    public class WebService : System.Web.Services.WebService<br />
    {<br />
<br />
        [WebMethod]<br />
        public List<Faculty> BindFaculties()<br />
        {<br />
            List<Faculty> facultyList = new List<Faculty>();<br />
            FacultyBL facultyBL = new FacultyBL();<br />
<br />
            try<br />
            {<br />
                return facultyBL.getAllFaculties();<br />
            }<br />
            catch (Exception ex)<br />
            {<br />
<br />
            }<br />
            finally<br />
            {<br />
                facultyBL = null;<br />
            }<br />
<br />
<br />
            return facultyList;<br />
        }<br />
    }<br />
<br />


I can call this webservice from jQuery using AJAX, but I have to use POST. If I use GET, I get this error

An attempt was made to call the method BindFaculties using a GET request, which is not allowed.

If I copy paste the url of the web service in my browser, I get this error

Request format is unrecognized for URL unexpectedly ending in '/BindFaculties'.


How come the asmx web method accepts post? I have written nothing to limit GET.

I want to use GET because I eventually want to create a RESTful API. How to do this?
Posted

1 solution

make your web.config of web service something like this.

XML
<configuration>
  <system.web>
    <webServices>
      <protocols>
        <add name="HttpGet"/>
        <add name="HttpPost"/>
      </protocols>
    </webServices>
  </system.web>
 </configuration>


and add this before webmethod starts
so the methos should be like
XML
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public List<Faculty> BindFaculties()
{
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900