I have scoured Google looking for this same issue and I cannot seem to find any help. Any assistance is appreciated. I have created a webservice asmx in C#:
[WebMethod]
[ScriptMethod()]
public ListObj GetList(string ListName)
{
SqlConnection DBConnection = new SqlConnection();
DBConnection.ConnectionString = ConfigurationManager.ConnectionStrings["SiteSqlServer"].ToString();
SqlDataReader DBReader = null;
SqlCommand query = new SqlCommand("SELECT Lists.Text, Lists.Value FROM Lists WHERE ListName = '" + ListName + "'", DBConnection);
List<string> text_list = new List<string>();
List<string> value_list = new List<string>();
DBConnection.Open();
DBReader = query.ExecuteReader();
while (DBReader.Read())
{
text_list.Add(DBReader["Text"].ToString());
value_list.Add(DBReader["Value"].ToString());
}
DBConnection.Close();
return new ListObj(text_list, value_list);
}
i am attempting to call that method using jquery:
<script type="text/javascript">
$(document).ready(function () {
$("#JoeTest").click(function () {
$.ajax({
type: "POST",
url: "/Portals/0/DnnListService.asmx/GetList",
data: {ListName: 'TestList'},
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Success: " + msg);
},
error: function (msg) {
alert("Failed: "+ msg.status + ": " + msg.statusText);
}
});
});
});
</script>
If I go directly to the asmx I can input my string and get the data back, no problem: http://screencast.com/t/JQmHYoz5c http://screencast.com/t/xDuMJe7v1A
However, the ajax call above is returning an error:
{"Message":"An attempt was made to call the method \u0027GetList\u0027 using a POST request, which is not allowed.","StackTrace":" at System.Web.Script.Services.RestHandler.GetRawParams(WebServiceMethodData methodData, HttpContext context)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
Any ideas on what the issue may be?