I wrote web service in ASP.NET, it has this address:
http://localhost/RouteGen/Service.asmx
Web Service has web method GetMessage
, it doesn't take any parameters and returns a string.
It's all right with web service, I call its methods from others ASP.NET apps or even from Android app.
Server code:
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
[WebMethod]
public string GetMessage() {
return "Hello World";
}
}
Now I need to call web method GetMessage
from javascript.
html page: (this web page has no connection with web service code, it's totally another project! You can consider that it is written in win notepad)
...
<body id="body1" onload="initialize()" style="behavior:url(webservice.htc)">
</body>
...
in initialize() method I'm calling:
...
service_init();
processResult();
And there're this functions:
function service_init()
{
body1.useService("http://localhost/RouteGen/Service.asmx?WSDL","TheService");
body1.TheService.callService("GetMessage");
}
function processResult(result)
{
alert(result);
}
So relults I have:
1)In IE processResult()
returns "undefined"
2)In Chrome and FireFox it doesn't work at all (simple alert after useService doesn't appear)
Where is the problem?How to make javascript invoke web method normally and from different browsers?