I tried a web service + ajax call as written by Fuxiang. I created the aspx page and the service (.asmx) and hosted it in the server in IIS. The code works perfectly when i run it in the local server.
When I call the same from a remote machine i get internal 500 error. Why is this so? The same happens when i try with angular instead of jquery ajax. What is the work around?
ERROR
Failed to load resource: the server responded with a status of 500 (Internal Server Error) Request format is unrecognized for URL unexpectedly ending in '/HelloWorld'.
Here's the code:
aspx
<script>
//no paras to call
$(document).ready(function () {
$.ajax({
type: "POST",
contentType: "application/text",
url: "Test_WebService.asmx/HelloWorld",
data: {},
dataType: 'text',
error: function (err) {
$('#content').html(err);
},
success: function (result) {
$('#content').html(result);
// alert(result);
}
});
$('#loading').ajaxStart(function () {
$(this).show();
}).ajaxStop(function () {
$(this).hide();
});
});
</script>
<body>
<form id="form1" runat="server">
<div id="content">
</div>
<div id="loading">
service is handling,please wait......
</div>
</form>
</body>
asmx
[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 Test_WebService : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
System.Threading.Thread.Sleep(2000);
return "Hello World";
}
}
Update:
I have added the following in web config and it hasn't made a change:
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
I have registered the asp version in the web server, still it does not work
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis -i