I wrote a simple ASP.NET WebService Precompiled it and hosted it in a virtual directory.
Webservice code:
namespace Test.Services
{
/// <summary>
/// Summary description for AgentService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]
public class TestService : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public string SayHello(string name)
{
return "Hello, " + name;
}
}
}
Javascript code to access this webservice:
function SayHello() {
var serviceURL = "http://172.42.100.47/TestService/TestService.asmx/SayHello";
var requestData = "{name:'" + $('#txtName').val() + "'}";
$.ajax({
type: 'POST',
contentType: 'application/json; charset=utf-8',
url: serviceURL,
data: requestData,
dataType: 'json',
success: function(result){
alert(result.d);
}
});
}
If i use this function from a page hosted in the same IP then it works as expected. But if I access it from a different IP (eg: 127.0.0.1) then I get "Permission Denied" in IE and "404 Object Not Found" in FireFox.
How do I write a webservice using ASP.NET that can be used remotely from anywhere and what should be the Javascript to consume it.
Every example that I found referred to a WebService hosted in the same project directory.