I have following asmx service
[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 DinnerService : System.Web.Services.WebService
{
List<Dinner> dinners;
public DinnerService()
{
dinners = new List<Dinner>();
}
[WebMethod]
[ScriptMethod(UseHttpGet = false, ResponseFormat = ResponseFormat.Json)]
public Dinner HelloWorld()
{
var dinner = new Dinner { DinnerID = 1, Host = "Ahsan", RSVP = "Some People", Venue = "Lahore" };
return dinner;
}
}
and I'm calling it from jQuery on page load event of webform as follows
$(function () {
$.ajax({
type: 'post',
url: 'http://localhost:1901/DinnerService.asmx/HelloWorld',
dataType: 'json',
data:{},
contentType: "application/json; charset=utf-8",
success: function (data) {
$('#res').html(data.d.DinnerID);
alert(data.d.Host);
}
});
});
It works fine on IE but in Firefox and Chrome it shows internal server error and response is like:
Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'
This is very strange for me, why it's working on one browser and not on others. I am using Visual studio 2010 and .NET 3.5 for the service. Going to WCF for this particular case is not the option. Response on the internet could not help me solve the issue. What exactly is happening here?