从Android浏览器调用Web服务时出现问题

从Android浏览器调用Web服务时出现问题,android,browser,service,web,Android,Browser,Service,Web,我一直在努力从Android浏览器(Android 2.2)调用html5中的一个简单web服务。它在Android浏览器上不起作用。但是,如果我在PC上运行它,它会工作。当我点击按钮时,什么也不会发生。我已经上网两个星期了。但是,没有得到任何工作。下面是html页面的代码。请帮忙 <html> <head> <title>UseSwap</title> <script language="JavaScript">

我一直在努力从Android浏览器(Android 2.2)调用html5中的一个简单web服务。它在Android浏览器上不起作用。但是,如果我在PC上运行它,它会工作。当我点击按钮时,什么也不会发生。我已经上网两个星期了。但是,没有得到任何工作。下面是html页面的代码。请帮忙

 <html>
  <head>
   <title>UseSwap</title>
    <script language="JavaScript">
     function InitializeService(){
      service.useService("http://localhost:2913/WebServicesUsingCSharp/WebService.asmx?wsdl",
    "GetAgeService");

     }
     var StrYear, StrMonth, StrDay;
     function GetAge(){
      StrYear = document.DemoForm.StringYear.value;
      StrMonth = document.DemoForm.StringMonth.value;
      StrDay = document.DemoForm.StringDay.value;
      service.GetAgeService.callService("GetAge", StrYear, StrMonth, StrDay);
     }
     function ShowResult(){
    alert(event.result.value);
      }
     </script>
    </head>
     <body onload="InitializeService()" id="service"
    style="behavior:url(webservice.htc)" onresult="ShowResult()">
       <form name="DemoForm">
       Year : <input type="text" name="StringYear"/>
       Month : <input type="text" name="StringMonth"/>
       Day : <input type="text" name="StringDay"/>
       <button onclick="GetAge()">Get Age</button>
      </form>
     </body>
 </html>

使用交换
函数InitializeService(){
service.useService(“http://localhost:2913/WebServicesUsingCSharp/WebService.asmx?wsdl",
“GetAgeService”);
}
变量StrYear,StrMonth,StrDay;
函数GetAge(){
StrYear=document.DemoForm.StringYear.value;
StrMonth=document.DemoForm.StringMonth.value;
StrDay=document.DemoForm.StringDay.value;
service.GetAgeService.callService(“GetAge”,StrYear,StrMonth,StrDay);
}
函数ShowResult(){
警报(事件、结果、值);
}
年份:
月份:
日期:
变老
问候,,
Parshant。

您的html引用同一台机器上的服务

我认为你的android手机上没有运行webservice


localhost
替换为服务器的ip

您的html引用同一台机器上的服务

我认为你的android手机上没有运行webservice


用服务器的ip替换
localhost

我尝试用服务器ip地址替换“localhost”。但是,它没有工作。是否可以通过android手机访问服务器?i、 你能从你的HTMLBroser得到你服务的html页面吗?我正在Emulator上运行代码。当我试图从Android Emulator上加载的html页面调用web服务时,什么也没发生。根据前面的评论,您需要能够从其他机器访问“服务器”。如果这是一台本地开发计算机,请确保它在防火墙中打开了相关端口。我尝试用服务器IP地址替换“localhost”。但是,它没有工作。是否可以通过android手机访问服务器?i、 你能从你的HTMLBroser得到你服务的html页面吗?我正在Emulator上运行代码。当我试图从Android Emulator上加载的html页面调用web服务时,什么也没发生。根据前面的评论,您需要能够从其他机器访问“服务器”。如果这是本地开发计算机,请确保它在防火墙中打开了相关端口。